-
Does it ever end
please explain wats wrong
Code:
#include <iostream>
using namespace std;
int main();
{
int number=9;
int guess;
cout << "What day is my birthday on (Between 1 and 31)" << endl;
cout << "Enter your guess, please?";
cin >> guess
if(guess == number)
{
cout << "Incredible, you are correct!" << endl;
}
else if(guess < number && > 0)
{
cout << "Your guess is too low" << endl;
}
else if(guess > number && < 32)
{
cout << "Your guess was too high" << endl;
}
else
{
cout << "You either entered a number below 1, above 31 or a decimal. Incorrect, please try again" << endl;
}
return 0;
}
plz :mad:
-
Semi-colon on line 4 after main() that shouldnt be there.
Missing semi-colon on line 12.
Improperly formed conditional on lines 17 and 21.
-
wat is wrong with conditions on 17 and 21?
-
Consider:
guess < number && > 0
So we have:
guess < number
which is ok.
Then we have:
> 0
So what is compared to to see if it is greater than 0?
-
so wat, do i use == instead?
-
No you use:
guess < number && guess > 0
-
-
more
fixed wat u said but still wont work
Code:
#include <iostream>
using namespace std;
int main();
int number=9;
int guess;
cout << "What day is my birthday on (Between 1 and 31)";
cout << "Enter your guess, please?";
cin >> guess;
{
if(guess == number)
{
cout << "Incredible, you are correct!" << endl;
}
else if(guess < number && guess > 0)
{
cout << "Your guess is too low" << endl;
}
else if(guess > number && guess < 32)
{
cout << "Your guess was too high" << endl;
}
else
{
cout << "You either entered a number below 1, above 31 or a decimal. Incorrect, please try again" << endl;
}
return 0;
}
-
decided to add this but no improvement although i knew it wouldn't fix it, just the app wont close
Code:
#include <iostream>
#include <limits>
using namespace std;
int main();
int number=9;
int guess;
cout << "What day is my birthday on (Between 1 and 31)";
cout << "Enter your guess, please?";
cin >> guess;
{
if(guess == number)
{
cout << "Incredible, you are correct!" << endl;
}
else if(guess < number && guess > 0)
{
cout << "Your guess is too low" << endl;
}
else if(guess > number && guess < 32)
{
cout << "Your guess was too high" << endl;
}
else
{
cout << "You either entered a number below 1, above 31 or a decimal. Incorrect, please try again" << endl;
}
cin.ignore();
cin.get();
return 0;
}
plz
-
Here's the code, assuming that you arent quite running it from command line and so need the cin.ignore() at the end.
Code:
#include <iostream>
using namespace std;
int main()
{
int number = 9;
int guess;
cout << "What day is my birthday on (Between 1 and 31)" << endl;
cout << "Enter your guess, please?";
cin >> guess;
if (guess == number)
{
cout << "Incredible, you are correct!" << endl;
}
else if (guess < number && guess > 0)
{
cout << "Your guess is too low" << endl;
}
else if (guess > number && guess < 32)
{
cout << "Your guess was too high" << endl;
}
else
{
cout << "You either entered a number below 1, above 31 or a decimal. Incorrect, please try again" << endl;
}
cin.ignore(2);
return 0;
}
If you have a problem, describe it.
-
You put:
int main();
It should be:
int main()
{
That's a problem.
-
thankz
thankz so much , i never realised that before