Question

In: Computer Science

Calculate the ideal age of a spouse. Enter either m or f from the keyboard in...

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.

Solutions

Expert Solution

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:


Related Solutions

Write an interactive C program that asks a user to enter a sentence from the keyboard,...
Write an interactive C program that asks a user to enter a sentence from the keyboard, and prints the sentence with all the words spelled backwards. Note: you may assume that each sentence will have at most 50 characters and each word is separated by a space. Sample code execution: bold information entered by user enter a sentence: hello ece 175 class olleh ece 571 ssalc continue (q to quit)? y enter a sentence: May the force be with you...
write a C++ program that uses function swap to enter three real value from the keyboard...
write a C++ program that uses function swap to enter three real value from the keyboard and outputs there in order from minimum to the maximum. For example 10,100,30 if were entered then the output would be 10,30,100. The program should use function get_data(a,b,c) and print_data(a,b,c)
Nice Number Programming: Nice program ask user to enter three integers from keyboard (java console), the...
Nice Number Programming: Nice program ask user to enter three integers from keyboard (java console), the three integers represent left bound, right bound and arbitrary digit ‘m’, where left bound is less than right bound. Program should print all nice numbers in the given range that doesn’t contain digit 'm'. The number is nice if its every digit is larger than the sum of digits which are on the right side of that digit. For example 741 is a nice...
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
a) Calculate the change in entropy on heating an ideal gas from 300K to 500K at...
a) Calculate the change in entropy on heating an ideal gas from 300K to 500K at constant pressure. b) Calculate the change in entropy on heating an ideal gas from 300K to 500K at constant volume. c) why these answers are different. Please explain each steps.
Calculate the concentration of all species in a 0.175 M solution of H2CO3. Enter your answers...
Calculate the concentration of all species in a 0.175 M solution of H2CO3. Enter your answers numerically separated by commas. Express your answer using two significant figures. [H2CO3], [HCO3^-], [CO3^2-], [H3O^+], [OH^−] =
Calculate the concentration of all species in a 0.135 M solution of H2CO3. Enter your answers...
Calculate the concentration of all species in a 0.135 M solution of H2CO3. Enter your answers numerically separated by commas. Express your answer using two significant figures.
calculate the freezing point of water (Kf= 1.86 C/m) for an ideal solution of sodium phosphate...
calculate the freezing point of water (Kf= 1.86 C/m) for an ideal solution of sodium phosphate which has a concetration of 3.25 m .
Lipoproteins in Lipid Transport Lipids either enter the body through diet, are released from storage in adipose tissue
Lipoproteins in Lipid Transport Lipids either enter the body through diet, are released from storage in adipose tissue, or are manufactured in the liver. All lipids are transported in the blood. Because blood is aqueous and lipids are nonpolar, lipids must form associations with other molecules to form lipoproteins that can be transported in blood. Chylomicrons, very-low-density lipoproteins (VLDLs), intermediate-density lipoproteins (IDLs), low-density lipoproteins (LDLs), and high-density lipoproteins (HDLs) are five types of lipoproteins. Chylomicrons exclusively carry lipids from the...
Calculate deltaS total for the isothermal irreversible free expansion of 1.00 mol of ideal gas from...
Calculate deltaS total for the isothermal irreversible free expansion of 1.00 mol of ideal gas from 8.0 L to 20.0 L at 298 K
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT