Hello
I am using Microsoft Visual Studio 2010 and i have recently typed these codes, afterwards i have launched build and it was successful but when i launch run the console only prints Enter a number less than 10 or greater than 100:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
int main()
{
int x;
std::cout << "Enter a number less than 10 or greater than 100: ";
std::cin >> x;
std::cout << "\n";
if (x >= 10)
if (x > 100)
std::cout << "More than 100. Thanks!\n";
else
std::cout << "Less than 10. Thanks!\n";
return 0;
}
Thank you guys for replying i appreciate it, wildblue the truth is i am still a beginner learning the C++ Programming Language from Sams Teach Yourself C plus plus in One Hour a Day 6th Edition so i am not sure what is the problem since i have followed the instructions accordingly.
These are the results the code gives. It doesn't accurately represent what was entered. (I just added in a line to output a little more text and the value actually entered.) If you want the else to pair up with the first if, then you can add the set of curly braces I used in the earlier post.
Enter a number less than 10 or greater than 100:
I entered 5. The if/else thinks this:
Enter a number less than 10 or greater than 100:
I entered 10. The if/else thinks this: Less than 10. Thanks!
Enter a number less than 10 or greater than 100:
I entered 50. The if/else thinks this: Less than 10. Thanks!
Enter a number less than 10 or greater than 100:
I entered 100. The if/else thinks this: Less than 10. Thanks!
Enter a number less than 10 or greater than 100:
I entered 150. The if/else thinks this: More than 100. Thanks!
I appreciate your help wildblue but i did add the braces and yet the output is the same.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
int main()
{
int x;
std::cout << "Enter a number less than 10 or greater than 100: ";
std::cin >> x;
std::cout << "\n";
if (x >= 10)
{
if (x > 100)
std::cout << "More than 100. Thanks!\n";
}
else
std::cout << "Less than 10. Thanks!\n";
return 0;
}