I would like to get this to show the amount of money complete with a $ and to two decimal places, I know how to accomplish this in C# but not C++. Also the age so I don't have to separate them into two cout statments. Thanks for your help.
//declaring header mains
#include <iostream>
#include <string>
usingnamespace std;
//Method: The main method
//Purpose: To get the users name, age, and money; and return the information
//Parameters: Name as string, age as integer, and money as a float value
//Returns: Users inputted name, age, and money
int main()
{
//Declaring variables
string fullName;
int age;
float money;
//Promt the user to enter their age
cout << "Please enter your age: ";
cin >> age;
//Prompt the user to enter their amount of money
cout << "Please tell me how much money you have: ";
cin >> money;
//Prompt the user to enter their full name; adding a clear for the input buffer
cout << "Please enter your full name: ";
cin.ignore();
getline( cin, fullName );
//Display the name back to the user; and adds another line
cout << "Thank you " << fullName << endl;
//Display the age back to the user
cout << "You are " << age;
cout << " years old; ";
//Display the amount of money back to the user
cout << "\nand you have $" << money;
cout << " in your pocket.";
//Giving the user an ending message
cout << "\nGoodbye .....\n";
//Keeping the window open
system("PAUSE");
//Return zero
return 0;
}
2) I I understand you correctly you want to do that: cout << "You are " << age << " years old;\nand you have $" << money << " in your pocket.";
And please, read my first answer in your other thread and use one of the methods there. (either ignoring everything until newline or skipping whitespace character)
Your current solution violates C++ streams console philosophy: whitespaces are not important
//declaring header mains
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
//Method: The main method
//Purpose: To get the users name, age, and money; and return the information
//Parameters: Name as string, age as integer, and money as a float value
//Returns: Users inputted name, age, and money
int main()
{
//Declaring variables
string fullName;
int age;
float money;
//Promt the user to enter their age
cout << "\nPlease enter your age: ";
cin >> age;
//Prompt the user to enter their amount of money
cout << "\nPlease tell me how much money you have: ";
cin >> money;
//Prompt the user to enter their full name; adding a clear for the input buffer
cout << "\nPlease enter your full name: ";
cin.ignore();
getline( cin, fullName );
//Display the name back to the user; and adds another line
cout << "\nThank you " << fullName << endl;
//Display the age back to the user
cout << "You are " << age << " years old";
//Display the amount of money back to the user
cout << "\nand you have $";
std::cout << std::fixed << std::setprecision(2) << money << " in your pocket";
//Giving the user an ending message
cout << "\nGoodbye .....\n";
//Keeping the window open
system("PAUSE");
//Return zero
return 0;
}