I am losing my mind

This is so basic yet i cant seem to get it and it is frustrating me Basically I need to input the world population and country population, and get what percentage the countries population is of the worlds. It seems so basic yet i cant get it.
This is what i have


#include <iostream>
using namespace std;

int main()
{
long long int worldPop, countryPop;
int ratio = 0.0;

string country;

cout <<"Enter the world population ";
cin >> worldPop;

cout <<"Enter the name of the country ";
cin >> country;

cout <<"Enter the population of the country ";
cin >> countryPop;

ratio = countryPop/worldPop;

cout <<"The population of "<< country << " is " << ratio <<"% of the world population";
return 0;
}
int is for whole numbers. doubles are for fractions.
I added a *100 to the ratio so that it makes more sense as a percentage.

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
#include <iostream>
using namespace std;

int main()
{
	long long int worldPop, countryPop;
	double ratio = 0.0;

	string country;

	cout << "Enter the world population ";
	cin >> worldPop;

	cout << "Enter the name of the country ";
	cin >> country;

	cout << "Enter the population of the country ";
	cin >> countryPop;

	ratio = double(countryPop) / double(worldPop) * 100;

	cout << "The population of " << country << " is " << ratio << "% of the world population";

	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main()
{
	long long int worldPop {}, countryPop {};

	std::string country;

	std::cout << "Enter the world population ";
	std::cin >> worldPop;

	std::cout << "Enter the name of the country ";
	std::cin >> country;

	std::cout << "Enter the population of the country ";
	std::cin >> countryPop;

	std::cout << "The population of " << country << " is " << countryPop * 100.0 / worldPop << "% of the world population";
}

Topic archived. No new replies allowed.