Question:
does anybody know how to do this c++ program?
chingonsonson
2010-11-28 16:38:28 UTC
Pancake Glutton
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
arrays

Write a program that asks the user to enter the number of pancakes eaten for breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Once the data has been entered the program must analyze the data and output which person ate the most pancakes for breakfast.

★ Modify the program so that it also outputs which person ate the least number of pancakes for breakfast.

★★★★ Modify the program so that it outputs a list in order of number of pancakes eaten of all 10 people.
i.e.
Person 4: ate 10 pancakes
Person 3: ate 7 pancakes
Person 8: ate 4 pancakes
...
Person 5: ate 0 pancakes
Four answers:
SomeGuy
2010-11-28 17:38:04 UTC
1. To start off you'll want to make your array

int Person [10];



2. Now you'll want to input how much each person ate. You can do this with a for loop since it's considered a counted loop



for (int i = 0 ; i <= 9 ; i++)

cin >> Person [i];



3. Now you'll want to keep track of the max value and the min value.

There's many ways to go about this. But I'll show you one method.



make a boolean variable named "setminmax"



bool setminmax = false;



Now you remember the for loop in step 2? We're going to add to that. but first we need to make 2 more integer variables



int max , min;



Now for our for loop



for (int i = 0 ; i <= 9; i ++) {

cin >> Person [i];

if (!setminmax){

Person [i] = Min;

Person [i] = Max;

setminmax = true;}



if (Person [i] > Max)

Person[i] = Max;

else if (Person [i] < Min )

Person [i] = Min;



} // End of If Statement

}



Now that's a lot of code but I'll explain it

First I got the value of the first person.

Then I made my if statement

if (!setminmax){

Person [i] = Min;

Person [i] = Max;

setminmax = true;}



This basically sets the value of person one to the Min and Max Value.

We do this because when you enter the value for person 2 then the Max or Min value will change.



if (Person [i] > Max)

Person[i] = Max;

else if (Person [i] < Min )

Person [i] = Min;



You see this statement after. this will basically change the value of Max and Min depending on what you enter for the next Person



For Example say the value for Person [0] = 5;

if the value of Person [1] = 10 then the value of Person[1] will be equal to Max



4. Now to Display the max value you could simply put

cout << Max;



But the problem is that more than one person might have the same Max value so we have to create another for loop to display the max value.



for (int i = 0 ; i <= 9 ; i ++) {

if (Person [i] == Max)

cout << Person [i] << " ate " << Max << " Pancakes" << endl;

}







5. You'll do the same for Min



for (int i = 0 ; i <= 9 ; i ++) {

if (Person [i] == Min)

cout << Person [i] << " ate " << Min << " Pancakes" << endl;

}



6. To display them in order from highest to lowest I'll let you figure that part out because I don't want to do all your hw for you.



So I Hope This Helped :D



If you have any further questions don't be afraid to ask
2010-11-29 00:59:47 UTC
Your first step should be to write out the steps you'd take. Once you do that, put your code around those steps and make what you've written in to comments.



As the other person said, without code it's very difficult to tell you where you've gone wrong and what approach you should be trying.



I'd be using something along the lines of a hash table where you have a key:value pair. That way you can just sort on your data and print it out accordingly.
?
2010-11-29 04:39:27 UTC
I would make a vector of this and use the sort method on it. you might want to make a class out of it, that way your data tuples remain paired. it's going to require a little footwork to make the sort compare routine for the class.
tbshmkr
2010-11-29 00:50:32 UTC
Show your code.

=

Then people will help you get it working right.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...