Question
This is for Advanced Object-Oriented. Please do the following question as instructed by the information. Keep it as simple as possible. The program needs to
This is for Advanced Object-Oriented. Please do the following question as instructed by the information. Keep it as simple as possible.
The program needs to ask users to provide:
User's name (string value, can be multiple words)
User's gender (string value)
User's age (integer value)
User's weight today (real value, unit: kg)
User's exercise type today (string value, can be multiple words) and the exercise time (real value, unit: minute)
Need to ensure the inputs of age, weight, and exercise time are of numeric values. E.g., if users give an age input as 'sixty', the program needs to inform users that it's a bad input and ask for another input until the input is valid.
Print the user's information to the console as follows:
User's name (Gender, Age)
Weight: today's weight kg
Exercise: today's exercise type (time mintues)
=========================================================================================================================================
The following code is what I have, please use this a base and keep it simple. Please use while loops.
#include
int main() {
string name; cout << "Enter your name: " << endl; getline(cin, name);
string gender; cout << "Enter your gender: " << endl; getline(cin, gender);
string exercise; cout << "Enter type of exercise: " << endl; getline(cin, exercise);
int age; //cout << "Enter your age: " << endl; //cin >> age;
if (age > 0) {
cout << "Enter your age: " << endl; cin >> age;
} else {
cout << "Please enter numeric values!";
}
double weight; //cout << "Enter your weight: " << endl; //cin >> weight;
if (weight > 0) {
cout << "Enter your weight: " << endl; cin >> weight;
} else {
cout << "Please enter numeric values!";
}
double time; //cout << "Enter lenght of exercise: " << endl; //cin >> time;
if (time > 0) {
cout << "Enter lenght of exercise: " << endl; cin >> time;
} else {
cout << "Please enter numeric values!";
}
cout << name << "(" << gender << "," << age << ")" << endl; cout << "Weight: " << weight << endl; cout << "Exercise: " << exercise << "(" << time << "minutes)" << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started