Pankcake Array problem

I am currently working on an answer to the Pancake Array exercise found here:http://www.cplusplus.com/forum/articles/12974/

I am interested in knowing how to maybe make a loop for this instead of just using the cout statement over and over again.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
using namespace std;
int pancakes[9];
string amount = "How many pankcakes did person ";

int main () 
{
    cout<<"Welcome to my panckae project!"<<endl;//This project will teach me the use of arrays and help me with user input and output
    cout<<amount<<"1 eat? \n";
    cin>>pancakes[0];
    cout<<amount<<"2 eat? \n";
    cin>>pancakes[1];
    cout<<amount<<"3 eat? \n";
    cin>>pancakes[2];
    cout<<amount<<"4 eat? \n";
    cin>>pancakes[3];
    cout<<amount<<"5 eat? \n";
    cin>>pancakes[4];
    cout<<amount<<"6 eat? \n";
    cin>>pancakes[5];
    cout<<amount<<"7 eat? \n";
    cin>>pancakes[6];
    cout<<amount<<"8 eat? \n";
    cin>>pancakes[7];
    cout<<amount<<"9 eat? \n";
    cin>>pancakes[8];
    cout<<amount<<"10 eat? \n";
    cin>>pancakes[9];
    cout<<"Person 1 ate: "<<pancakes[0]<<" pancakes\n";
    cout<<"Person 2 ate: "<<pancakes[1]<<" pancakes\n";
    cout<<"Person 3 ate: "<<pancakes[2]<<" pancakes\n";
    cout<<"Person 4 ate: "<<pancakes[3]<<" pancakes\n";
    cout<<"Person 5 ate: "<<pancakes[4]<<" pancakes\n";
    cout<<"Person 6 ate: "<<pancakes[5]<<" pancakes\n";
    cout<<"Person 7 ate: "<<pancakes[6]<<" pancakes\n";
    cout<<"Person 8 ate: "<<pancakes[7]<<" pancakes\n";
    cout<<"Person 9 ate: "<<pancakes[8]<<" pancakes\n";
    cout<<"Person 10 ate:"<<pancakes[9]<<" pancakes\n";
    std::cin.ignore();
    std::cin.get();
}


Please note that I am extremely new to programming in C++! Thanks
-Will Malina
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
using namespace std;
int pancakes[9];
string amount = "How many pankcakes did person ";


int main () 
{
    std::cout<<"Welcome to my panckae project!"<<std::endl;//This project will teach me the use of arrays and help me with user input and output
    for (int x=1;x<=10;x++)
    {
        std::cout<<amount<<x<<" eat? ";
        cin>>pancakes[x];
    }
    int a=1;
    int numofpan = pancakes[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
    for (numofpan=pancakes[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];numofpan<=10;numofpan++)
    {
        std::cout<<"Person "<<a++<<" ate: "<<pancakes[numofpan]<<" pancakes\n";
    } 
    std::cin.get();
}


Alright thats what I just made.. Any improvements to make?

I do get an error when I run the program though... Right after I enter all the values
Topic archived. No new replies allowed.