If you want to allow the user to enter another number, you're going to need a loop.
Line 20: This is going to cause you to exit the program immediately and return an indication to the operating system that the program failed (assuming a is non-zero).
first off like to say love your "noob" reference for the title
second if you want to repeat it more then once use a do while loop that way it will read it once and continue with it ex)
do
{
//////
place here ur code
//////
/// would you like to try again////////
}while(ans == 'n')
I got lost. in while(ans == 'n') shall i replace them with something or just copy paste in code?I forgot to mention its my second year of c++ at school,take me easier :D
do
{
/// what ever is between these scopes repeat once no matter what
// the while loop is waiting for your input so
// create another variable char and ask for the user to enter there answer y for yes again
// or n for no
cout << "would you like to try again" << endl;
cin >> ans;
}while(ans == 'y')
#include <iostream>
#include <limits>
usingnamespace std;
int main()
{
char ans;
int Clue;
cout << "Guess the number!Its bigger than 1 and smaller than 50"<<endl;
int a;
cin >>a;
if(a==6)
{
cout << "You guessed it!"<<endl;
}
elseif(a!=6)
{
cout << "Wrong,try again!" <<endl;
cout << "Do you need a clue?Type 'Clue'"<<endl;
if(cin>>Clue)
{
cout <<"It's smaller than 25"<<endl;
}
}
cout<<"Would you like to try again?Type 'y' for yes and 'n' for no."<<endl;
cin>>ans;
if(ans == 'n')
{
return 0;
}
elseif(ans == 'y')
return a;
When I type Clue,<<Would you like to try again?Type 'y' for yes and 'n' for no.>> pops out.Why?I also want to add the possibility to choose if you want to continue guessing or stop.