| jricardolopez69 (2) | |
|
I have an assignment due for this sunday, and I would like to see if some one can guide me to succeed on this. this is the problem. Write a C++ program that does the following: Print a menu to start with these choices: A - Enter female Data B - Enter male Data C - quit If the user enters A or B, have the user enter the height and weight then print the condition of low, target, or high. The program should be in a loop that until the user chooses C, the program will again ask for more input. Females: Height = 58 - 64, Low = weight 100 - 114, Target = weight 115 - 133 High = weight 134 - 152 Height = 65 - 71, Low = weight 117 - 135, Target = weight 136 - 156 High = weight >= 157 Males: Height = 61 - 67, Low = weight 123 - 133, Target = weight 134 - 150, High = weight 151 - 167 Height = 68 - 75, Low = weight 137 - 155, Target = weight 156 - 175, High = weight >= 176 Now I am being asked to do the next: Modify the program from last week to such that the user has the choice of entering either 5 males, 5 females, or quitting (the while loop should be retained to repeat the menu until the user chooses to quit. The names, weights, and heights of the 5 people should be stored into arrays. The program should print the list of names, weight, height, and category. The program also needs to have a function that prints a header (return type of void). It also needs a function that calculates the average height of all 5. The prototype for this will be: double average (int ht0, int ht1, int ht2, int ht3, int ht4); Any help will be appreciated, thank | |
|
|
|
| Zhuge (2974) | |
| Do you not understand what the problem is asking? Or is there some part of the algorithm you are having trouble implementing? | |
|
|
|
| jricardolopez69 (2) | |
|
//This is what I have, but I am not available to range the low, target, high weight to each person of the 5 individuals. I am available to see the height and weight but I can not categorize them in a range of low, target, or high. #include <iostream> #include <string> #include <array> //#include "StandardIncludes.h" using namespace std; #define MAX_PEOPLE 5 int GetHeight() { int height; std::cout << "Enter the person's height: "; std::cin >> height; return height; } int GetWeight() { // do the same thing here int weight; std::cout<< "Enter the person's weight:"; std::cin>> weight; return weight; } std::string GetName () { // Ask for the name std::string name; std::cout<< "Enter the person's name: "; std::cin>>name; return name; } void CheckPerson(std::string name, int weight, int height, bool sex) { // Checking Bob (M) // Checking Sue (F) // Weight 170 (Overweight) // Height 9 (Short) // Print the name std::cout << "Checking " << name << ":" << std::endl << " Height: " << height << ", Weight: " << weight << std::endl; if(sex) { // male }else { // Female if(height < 65) { // Short female if(weight < 115) std::cout << " Short female with low weight" << std::endl; else if(weight < 134) std::cout << " Short female with good weight" << std::endl; else std::cout << " Short female with high weight" << std::endl; }else { // Tall female if(weight < 156) // low std::cout << "Unfinished" << std::endl; else if(weight < 176) //good std::cout << "Unfinished" << std::endl; else //high std::cout << "Unfinished" << std::endl; } } std::cout << std::endl; } int main() { // Person people[] = new Person[5]; std::array<int, MAX_PEOPLE> weights; std::array<int, MAX_PEOPLE> heights; std::array<bool, MAX_PEOPLE> sex; std::array<std::string, MAX_PEOPLE> names; // Keep track of how many people have been entered int selectionCount = 0; // Get the input for(int selectionIndex = 0; selectionIndex < MAX_PEOPLE; selectionIndex++) { // do something std::cout << std::endl << "Make a selection: " << std::endl << "A - Male" << std::endl << "B - Female" << std::endl << "C - Quit" << std::endl ; char selection; std::cin >> selection; selection = tolower(selection); // Make the selection lower-case // Decide what to do with this selection if(selection == 'a') { // Male names[selectionIndex] = GetName(); heights[selectionIndex] = GetHeight(); weights[selectionIndex] = GetWeight(); sex[selectionIndex] = true; selectionCount++; }else if(selection == 'b') { // Female names[selectionIndex] = GetName(); heights[selectionIndex] = GetHeight(); weights[selectionIndex] = GetWeight(); sex[selectionIndex] = false; selectionCount++; }else if(selection == 'c') { // Quit break; } } cout<< " ----------------------------"<<endl; // Print values for(int personIndex = 0; personIndex < selectionCount; personIndex++) { CheckPerson(names[personIndex], weights[personIndex], heights[personIndex], sex[personIndex]); } // Wait for some input and keep the window open int wait; std::cin >> wait; } | |
|
|
|