Skip to main content
gamedev.net
🔒 Locked

do-while statement for c++

Started by pizzaman Oct 21, 2000 at 2:57 PM 5 replies 550+ views
Original Post
pizzaman
pizzaman
im trying to integrate a do while statement for my program but i get an error saying answer is an undeclared identifier. i just want the user to select yes or no to continue the program. heres my code. #include #include int main() { do{ cout<<"Package program in cm."<>length; if(length>10) cout<<"pass"; else if(length<10) cout<<"fail"; //width double width; cout<<"What is the width of the package?"; cin>>width; if(width>10) cout<<"Pass"; else if(width<10) cout<<"Fail"; double temp; double wind; cout<<"What is the temperature today?"; cin>>temp; cout<<"What is the wind speed?"; cin>>wind; cout<<"\n"; if((temp<5) || (wind>24)) cout<<"you aught to wear a cote today lad"<>strokes; if(strokes==1) cout<<"Hole in one"<>Answer; } while (Answer==''Y''); cout<<"This sure is a special program aint it"<
i am the best
djsteffey
djsteffey
you dont have answer declared anywhere
like char Answer;


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

pizzaman
pizzaman
oh i forgot about that. thanks, but still when i run it i have no errors but when i press y to repeat program it just says press any key to continue. and the program terminates. heres my code thats much shorter
#include
int main()
{
char Answer;
do{

double hand;
cout<<"how many hands do i have?";
cin>>hand;
if(hand==2)
cout<<"You are good!";
else if (hand>2)
cout<<"Im special!";

//repeat program
cout<<"Would you like to repeat program (Y/N)?";
cin>>Answer;
}while(Answer==''Y'');
cout<<"good for you"<
return(0);
}
i am the best
Shannon Barber
Shannon Barber
    
}while(Answer==''Y''||Answer==''y'');
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Mezz
Mezz
what he is saying is that you only check to see if the user pressed a capital Y, you also want to check for if they press a lowercase y.

-Mezz
pizzaman
pizzaman
thanks it all works.
i am the best

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.