If else misbehaving.
I have to write a program that outputs certain sentences based on the size of a number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
using namespace std;
int main()
{
double num;
cout << "Please enter a number. \n \n";
cin >> num;
{
if (num <= 0)
{
cout << "These are COLD numbers!! \n";
}
if else (num > 0 && <= 9)
{
cout << "These are DEDO numbers.\n";
}
else
{
cout << "These are WARM figures!!! Where's the pool? \n";
}
}
cout << "\n \n \n";
return 0;
}
|
I'm not sure why it isn't working. My friend's code looks the exact same as far as we can tell, and it works fine.
Thanks,
It's "else if", not "if else".
You might want to add 'num' in between the '&&' and the '<= 9'.
As maeriden said it is else if
not if else
There is no need to check if it is greater than 0 on line 19. If it is not less than or equal to 0 it can only be greater than 0.
Topic archived. No new replies allowed.