c++ type cast an arithmetic operation -


 #include <iostream>   int main()  {      long long w_popn;      long long us_popn;      std::cout << "enter world's population: ";      std::cin >> w_popn;      std::cout << "enter population of us: ";      std::cin >> us_popn;      std::cout << "the population of " << float (us_popn/w_popn) << "% of world population" << std::endl; return 0; } 

i doing exercise questions c++ primer plus, , stuck @ last print statement in code. particularly part type float (us_popn/w_popn). there quick , dirty way of turning results floating number in cout statement without having manually store results in float variable? ask because seems putting typecast of float in front of integer division in cout statement doesn't seem affect , end getting 0 result of truncation.

you have cast operands before division, otherwise casting result:

static_cast<float>(us_popn)/static_cast<float>(w_popn) 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -