Jump to content

Hello guys, I am trying to get the result of martianAge to show two decimal places after the whole number. Does anyone know how? setprecision(2) is not working because it is telling me that setprecision is not set, but it isn't a variable.

// 10/17/2014#include <iostream>#include <string>using namespace std; int main(){//setting up the variablesstring name = "" ;int earthAge = 0;const double martianYear = 1.88;double martianAge = 0; cout << "Let's calculate your Martian Age!" << endl;cout << "First, tell me your name." << endl;//getting input from the usergetline (cin, name); cout << "Welcome " << name << "!" << endl; cout << "What's your age in Earth years?";cin >> earthAge; martianAge = earthAge / martianYear;//displaying to the usercout << fixed << setprecision(2) << showpoint << "Wow, you are only " << martianAge << " years old on Mars!" << endl; system("pause");return 0;} 
Link to comment
https://linustechtips.com/topic/234756-c-homework-help/
Share on other sites

Link to post
Share on other sites

erm

There are 10 types of people in the world: Those who understand binary, and those who don't.

Just some helpful stuff: You're - You are, Your - Your car, They're - They are, Their - Their car, There - Over there.

 

Folding @ Home Install Guide and Links | My Build

 

Link to comment
https://linustechtips.com/topic/234756-c-homework-help/#findComment-3215187
Share on other sites

Link to post
Share on other sites

Yes?

 

Sorry haha, I replied with something completely wrong, then edited it to that, should have said why.

There are 10 types of people in the world: Those who understand binary, and those who don't.

Just some helpful stuff: You're - You are, Your - Your car, They're - They are, Their - Their car, There - Over there.

 

Folding @ Home Install Guide and Links | My Build

 

Link to comment
https://linustechtips.com/topic/234756-c-homework-help/#findComment-3215217
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×