Question
C++ Program - I cannot figure out how to get the program to loop (1 to 6) Calculate the ideal age of a spouse. Enter
C++ Program - I cannot figure out how to get the program to loop (1 to 6)
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)
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:
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 spouses 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 lower 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.
if gender=="M"
do male calculation
else
do female calculation
remember two = signs for comparison
You will need braces for code blocks.
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
/* * File: main.cpp * Author: AA * * Created on September 5, 2018, 5:46 PM */
#include
//Ideal Age of a Spouse
using namespace std;
/* * */ int main(int argc, char** argv) { string gender = " "; int age = 0; double idealage = 0; int counter; for (int counter =1; counter=6; counter++) { cout << "What is your gende?" << endl; cout << "Enter m for male and f for female: "; cin >> gender; cout << "What is your age? " ; cin >> age; gender[0]=toupper(gender[0]); if (gender == "M") { idealage = (age/2)+7; cout << "A " << gender << " age " << age << " has an ideal spouse with an age of " << idealage << endl; if (age > 60) { cout << "Robbing the cradle." << endl; } if (age < 25) { cout << "Too young to be married." << endl; } } else { idealage = (age*2)-14; cout << "A " << gender << " age " << age << " has an ideal spouse with an age of " << idealage << endl; if (age >60) { cout << "A gold digger." << endl; } if (age < 19) { cout << "Jail bait." << 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