Question

In: Computer Science

Write this program in a C++ language Calculate the ideal age of a spouse. Enter either...

Write this program in a C++ language 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


remember two = signs for comparison

You will need braces for code blocks

Solutions

Expert Solution

If you need any corrections/clarifications kindly comment

Please give a Thumps Up if you like the answer

Program

#include <iostream>
#include <cctype>
#include<string>
using namespace std;

int main()
{
        char gender;
        int age, total_ideal_age[2] = {0}, count[2] = {0}, ideal_age;
        for (int i = 0; i < 6; i++)
            {
                cout << "\nEnter gender(m or f):"; //Input from the keyboard either m or f
                cin >> gender;
                gender=toupper(gender);//Converting to uppercase
              
                cout<<"Enter age : ";// Enter age from keyboard
                cin>>age;
                if(gender=='M')//Determine if user is a male or female
                {
                    ideal_age=(age/2)+7;//Calculate Ideal age.
                    // Print the Gender as “Male” , and the age, and the ideal age calculated.
                    cout<<"Gender :Male"<<"\t"<<"Age : "<<age<<"\t"<<"Ideal Age of spouse: "<<ideal_age<<"\t";
                    if (age>60)
                    cout<<"Robbing the cradle."<<endl;
                    else if (age<25)
                    cout<<"Too young to be married"<<endl;
                    total_ideal_age[0]+=ideal_age;//Accumulate the total ideal age of a spouse for a male
                    count[0]+=1;//Accumulate the total count of males.
                  
                }
                else if (gender=='F')//Determine if user is a male or female
                {
                    ideal_age=(age*2)-14;//Calculate Ideal age.
                    // Print the Gender as “Female”, and the age, and the ideal age calculated.
                    cout<<"Gender :Female"<<"\t"<<"Age : "<<age<<"\t"<<"Ideal Age of spouse: "<<ideal_age<<"\t";
                    if (age>60)
                    cout<<"A gold digger"<<endl;
                    else if (age<19)
                    cout<<"Jail Bait"<<endl;
                    total_ideal_age[1]+=ideal_age;//Accumulate the total ideal age of a spouse for a female
                    count[1]+=1;//Accumulate the total count of females.
                }
              
            }
        cout<<"\nAverage ideal age of a spouse for a male :"<<(float)total_ideal_age[0]/count[0];
        cout<<"\nAverage ideal age of a spouse for a female :"<<(float)total_ideal_age[1]/count[1];

    return 0;
}


Output


Enter gender(m or f):3 m
Enter age : 28
Gender :Male   Age : 28   Ideal Age of spouse: 21  
Enter gender(m or f):m
Enter age : 70
Gender :Male   Age : 70   Ideal Age of spouse: 42   Robbing the cradle.

Enter gender(m or f):m
Enter age : 18
Gender :Male   Age : 18   Ideal Age of spouse: 16   Too young to be married

Enter gender(m or f):f
Enter age : 32
Gender :Female   Age : 32   Ideal Age of spouse: 50  
Enter gender(m or f):f
Enter age : 60
Gender :Female   Age : 60   Ideal Age of spouse: 106  
Enter gender(m or f):f
Enter age : 13
Gender :Female   Age : 13   Ideal Age of spouse: 12   Jail Bait

Average ideal age of a spouse for a male :26.3333
Average ideal age of a spouse for a female :56


Related Solutions

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...
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
In C Write a program that prompts the user to enter a Fahrenheit temperature calculate the...
In C Write a program that prompts the user to enter a Fahrenheit temperature calculate the corresponding temperature in Celsius and print it prompt the user if they want to do another temperature conversion if the user enters y, repeat 1), 2) and 3) if the user enters n, then print Bye and exit the program if the user enters any other character, ask the user to enter y or n only Note : c = (5.0/9.0)*(f-32.0) Sample output Enter...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol,...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol, omg, omw etc.), then translates it into English (e.g. laughing out loud, oh my god, on my way etc.). Also provide a mechanism to translate text written in English into SMS Language. needs to be able to translate at least 10 sms words
Using c# programming language Write a program that mimics a lottery game. Have the user enter...
Using c# programming language Write a program that mimics a lottery game. Have the user enter 3 distinct numbers between 1 and 10 and match them with 3 distinct, randomly generated numbers between 1 and 10. If all the numbers match, then the user will earn $10, if 2 matches are recorded then the user will win $3, else the user will lose $5. Keep tab of the user earnings for, let say 5 rounds. The user will start with...
Programming Language C++ Task 1: Write a program to calculate the volume of various containers. A...
Programming Language C++ Task 1: Write a program to calculate the volume of various containers. A base class, Cylinder, will be created, with its derived classes, also called child classes or sub-classes. First, create a parent class, Cylinder. Create a constant for pi since you will need this for any non-square containers. Use protected for the members. Finally, create a public function that sets the volume. // The formula is: V = pi * (r^2) * h Task 2: Create...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT