Hey I am starting to teach myself C++ for a school project and I have just started going through the book C++ Primer Plus and I am on Chapter 3 which is mostly talking about different ways to store variables like as a int or float. I am doing the problems they have at the end of the chapter. The one I am currently on asks to find the percent of the US population out of the Worlds population using long long to store the information. Here is my code.
Code:
#include <iostream>
int main()
{
using namespace std;
long long w_pop, us_pop;
long long percent;
cout<<"Enter current world's population: ";
cin>> w_pop;
cout<<endl<<"Enter current US population: ";
cin>> us_pop;
percent = (us_pop / w_pop) * 100;
cout<<endl<<"The currecnt US population is " << percent;
cout<<" percent of the world's population.";
return 0;
}
When I run the program it works for when the answer equal 1, like when I type in 5 for the worlds population and 5 for the US population, but I am not able to get it to display any numbers that actually would show a percent, like I do 5 for the world's and a 1 for the US population it will display a 0. I have looked in the book but I did not see anything that might fix it that I have learned so far. Is this caused by how the computer treats long long? Could someone explain what is causing me not to get a decimal answer? Thank you