In: Computer Science
Calculate the ideal age of a spouse. Enter either m or f from the keyboard in lower case. You may use string data for the gender. Convert the gender to upper case
Enter an age from the keyboard, probably an integer
You will need prompts telling the user what to enter.
Use an IF statement to determine if the person is a male or female. You do one calculation if the person is a male else you do another calculation if the person is a female.
Use a loop where you enter this data (loop for 1 to 6 ) so you will only have to run the program 1 time instead of 6 times.
m 28
m 70
m 18
f 32
f 60
f 13
For each set of data, print out the Gender, age, and Ideal Spouse's age, along with the following messages when they apply (the messages will be in the last column):
If a male over 60, print “robbing the cradle.”
If a male under 25, print “too young to be married”
if a female over 60, print “a gold digger”
if a female < 19 print “jail bait”
Plato's formula. A little bit out of date. You will be a gold digger or robbing the cradle if your age is over 40 because back then people only lived to be about 35 or so on the average.
For a male, his ideal spouse’s age is his age/2+7
For a female, her age*2-14
So, inside the loop
1. Input from the keyboard either m or f and an age
2. convert the m or f to upper or upper case
3. enter age from keyboard
4. Use an if to determine if user is a male or female. Use the appropriate syntax for your language. Calculate Ideal age.
5. Print the Gender as “Male” or as “Female”, and the age, and the ideal age you calculated.
6. Then print any matching messages on the same line
7. Accumulate the total idea age of a male spouse and of a female spouse and the count of males and females.
8. When you exit the loop the print the average idea age of a spouse for a male and the average ideal age of a spouse for a female.
if gender=="M"
do male calculation
else
do female calculation
In C++, please use visual studios and show output.
CODE IN C++:
#include <iostream>
using namespace std;
int main()
{
int i;
char gender;
int age,spouseAge=0;
for(int i=1;i<=6;i++){
cout<<"Enter Gender(m/f) and age respectively:";
cin >> gender >> age;
if(gender=='m'||gender=='M')
spouseAge = (age/2)+7;
else
spouseAge = (age*2)-14;
cout<<"Gender:"<<gender<<",
age:"<<age<<", spouse
age:"<<spouseAge<<endl;
if((gender=='m'||gender=='M') && age > 60)
cout << "robbing the cradle"<<endl;
else if((gender=='m'||gender=='M') && age < 25)
cout << "too young to be married"<<endl;
else if((gender=='f'||gender=='F') && age > 60)
cout << "a gold digger"<<endl;
else if((gender=='f'||gender=='F') && age < 19)
cout << "jail bait"<<endl;
}
}
OUTPUT: