benthejack
Programmer
hi i just started c++ yesterday (hence this is a rather remedial question) and have been following an internet tutorial.
anyway i finished the tutorial and decided to test my current knowledge by writing a basic program which asks if you can spell dog (hehe). but once i finished i found it was slightly faulty because it would always be correct if the word started with d
ie.. if you spelt dog dkg it would return positive
but if the first letter wasnt d ie you spelt it fog it would say it was wrong.
the code i used is below:
#include <iostream.h>
#include <stdlib.h>
long int wait;
int letter1(char &in1);
int letter2(char &in2);
int letter3(char &in3);
int main()
{
int X,Y,Z;
char A,B,C;
cout<<"can you spell dog??\n";
cin>>A>>B>>C;
//links to other functions
X=letter1(A);
Y=letter2(B);
Z=letter3(C);
if(X==1&&Y==1&&Z==1)
{
cout<<"yes!\n";
for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++){}}}}}
cout<<"\n";
main();
}
else
{
cout<<"no\n";
for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++){}}}}}
cout<<"\n";
main();
}
}
int letter1(char &in1)
{
switch(in1)
{
case 'd': case 'D':
return 1;
}
}
int letter2(char &in2)
{
switch(in2)
{
case 'o': case 'O':
return 1;
}
}
int letter3(char &in3)
{
switch(in3)
{
case 'g': case 'G':
return 1;
}
}
anyway i finished the tutorial and decided to test my current knowledge by writing a basic program which asks if you can spell dog (hehe). but once i finished i found it was slightly faulty because it would always be correct if the word started with d
ie.. if you spelt dog dkg it would return positive
but if the first letter wasnt d ie you spelt it fog it would say it was wrong.
the code i used is below:
#include <iostream.h>
#include <stdlib.h>
long int wait;
int letter1(char &in1);
int letter2(char &in2);
int letter3(char &in3);
int main()
{
int X,Y,Z;
char A,B,C;
cout<<"can you spell dog??\n";
cin>>A>>B>>C;
//links to other functions
X=letter1(A);
Y=letter2(B);
Z=letter3(C);
if(X==1&&Y==1&&Z==1)
{
cout<<"yes!\n";
for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++){}}}}}
cout<<"\n";
main();
}
else
{
cout<<"no\n";
for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++)
{for(wait=0;wait<=2000000000;wait++){}}}}}
cout<<"\n";
main();
}
}
int letter1(char &in1)
{
switch(in1)
{
case 'd': case 'D':
return 1;
}
}
int letter2(char &in2)
{
switch(in2)
{
case 'o': case 'O':
return 1;
}
}
int letter3(char &in3)
{
switch(in3)
{
case 'g': case 'G':
return 1;
}
}