I'm trying to make a program that tells the user to enter a population number and estimate what nation has the population number. Anyways, when I entered an integer,it pops up nothing. I entered "400,000,000 in but still nothing. I did the same thing that is under 400,000,000 like 200,000,000. Here's the code I'm working on. Ik there's only one but I'm trying to figure it out till I put more in.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*Enter a population number and estimate what nation has that population number*/
#include <iostream>
usingnamespace std;
int main()
{
int pop;
cout << "Enter a population number!\n";
cin >> pop;
if ( pop >= 313,955,00 )
cout << "United States";
return 0;
}
I'm not sure what you mean by more accurate but I can help you a bit. As your code is, if the user enters 1347350000(China), the program outputs the US. This is because you have the US first and 1347350000 > 313955000. You can fix this by either adding an upper limit to your if statements or rearrange the order so the countries with the highest population are at the top.
Well, you could put an "else" in there among the "ifs" and "else ifs," just in case someone decides to put in a population of -1 for some reason (or something similarly ridiculous).
Also, what would happen if someone decided to put commas in the input? (I really don't know).
And maybe in the output, you can put in the last census-based population for the country.