Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

pancake program

This topic is 2498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

well I am still working on my pancake program using c++. I found this problem online and it is good for me to brush up on my programming skills.
here is some code
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]#include[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][color="#000000"] [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]<iostream>[/font][/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]using[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][color="#000000"] [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]namespace[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][color="#000000"] std;[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]#define[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][color="#000000"] SIZE 3[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][color="#000000"] pancake[SIZE];[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][color="#000000"] main()[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]for[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]([/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] i=1;i<=SIZE;i++)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cout << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Enter number of pancakes eaten: "[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"];[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cin >> pancake;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cout << endl;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cout << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Person "[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] << i << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]": ate "[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] << pancake << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]" pancakes"[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] << endl;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cout << endl;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] hi = pancake[1];[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] lo = pancake[1];[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]for[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] ([/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] i=1; i<=SIZE;i++)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](hi < pancake)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]hi=pancake;[/font][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](lo > pancake)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]lo=pancake;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cout << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Highest value is "[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] << hi << endl;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cout << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Lowest value is "[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] << lo << endl;[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]for[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]([/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] x=1; x<=SIZE;x++)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]for[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]([/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] y=1; y<=SIZE;y++)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](pancake[y]<pancake[y+1])[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] temp = pancake[y+1];[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]pancake[y+1]=pancake[y];[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]pancake[y]=temp;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]for[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] ([/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] i=1;i<=SIZE;i++)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cout << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Person "[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] << i << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]": ate "[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] << pancake << [/font][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"pancakes"[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] << endl;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] test;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]cin >> test;[/font][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]return[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] 0;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]?[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]I am alomost finished all I need to do is sort the number of pancakes eaten from greatest to smallest.
such as[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]Person 4: ate 10 pancakes[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]Person 3: ate 7 pancakes[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]Person 5: ate 4 pancakes[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]and etc...[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]I just need a second pair of eyes and a little hint.Let me know if you need more information.[/font][/font]

Share this post


Link to post
Share on other sites
Advertisement


int hi = pancake[1];
int lo = pancake[1];
for (int i=1; i<=SIZE;i++)

[/quote]

The first element in an array is 0, and the last element in an array is SIZE-1.

Share this post


Link to post
Share on other sites
well this is where I am stuck.

[font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]for[/font][/font][/font][font=Consolas][size=2][font=Consolas][size=2] ([/font][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]int[/font][/font][/font][font=Consolas][size=2][font=Consolas][size=2] i=1;i<=SIZE;i++)[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]{[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]cout << [/font][/font][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515]"Person "[/font][/font][/font][font=Consolas][size=2][font=Consolas][size=2] << i << [/font][/font][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515]": ate "[/font][/font][/font][font=Consolas][size=2][font=Consolas][size=2] << pancake << [/font][/font][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515]"pancakes"[/font][/font][/font][font=Consolas][size=2][font=Consolas][size=2] << endl;[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]}[/font][/font]

Share this post


Link to post
Share on other sites

can you please elaborate on how to output who ate the pancake and how many he ate.

How about you google how to use arrays in C++? Here, I'll even give you a link. I'm certainly not trying to be rude, but google is your best friend when it comes to trying to figure something out. So is being able to clearly explain what the problem is, what you've tried, what you think it might be, etc.

Also, putting your code between [code ][/code ] tags (without the spaces) makes it nice and pretty. You already know about code tags though, so I'm not sure why you don't use them.

Share this post


Link to post
Share on other sites

can I get some code to work with.

Dude. Did you even click the link in my post? Did you even look at the example on that page that shows exactly how to print out an array? Have you even really tried to think about what fastcall22 said?

And yes, you can get some code to work with. From google.

Share this post


Link to post
Share on other sites

sorry but I some times try to take the easy way out, my apoligize to fastcall

That's not how it works here, and that's not how it works in life. If you want to learn how to program, you're going to have to work your butt off, because it's hard and it takes a lot of thinking and work. If you don't want to put effort into this, just quit now, because you're wasting your time and you're wasting the community's time. Otherwise, start putting effort into actually trying to learn something, and then (here's the important part) don't stop putting effort into it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!