Pancake glutton program. (C++)

Pancake glutton program. (C++)

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

Current version I have written: http://codepad.org/QHnt11CT

#include <iostream>
#include <string>


void bubbleSort(int arr[], int n) {
      bool swapped = true;
      int j = 0;
      int tmp;
      while (swapped) {
            swapped = false;
            j++;
            for (int i = 0; i < n - j; i++) {
                  if (arr[i] > arr[i + 1]) {
                        tmp = arr[i];
                        arr[i] = arr[i + 1];
                        arr[i + 1] = tmp;
                        swapped = true;
                  }
            }
      }
}

int main()
{
    int pancakeAmount[10];
    std::string consumers[10];

    for (int i = 0, j = 1; i < 10; i++, j++) {
        std::cout << "Please enter an amount of pancakes eaten by consumer"\
        " number " << j << "." << std::endl;
        std::cin >> pancakeAmount[i];
        std::cout << "Please enter the name of the person who ate that amount"\
        " of pancakes." << std::endl;
        getline(std::cin, consumers[i]);
    }

    std::cout << "The results from least amount eaten to the greatest amount"\
    " eaten are as follows:" << std::endl;

    bubbleSort(pancakeAmount, 10);

    for (int k = 0; k < 10; k++) {
        std::cout << pancakeAmount[k] << std::endl;
    }

    return 0;
}

That is the problem I am currently working on. As of right now, the first two objectives of this problem have been solved without any notable issues.

The third objective, however, is proving to be a bit more difficult. I am having a hard time designing/implementing a sorted list with the appropriate labels. In line 47 I am trying to obtain a name or label to give to the corresponding amount.

I am running into an issue where the console will accept the amount I want to assign, but will completely ignore the call to the getline() function and loop back into asking for another amount. When the getline() function is called before the "std::cin >> pancakeAmount[i]" is called, I can give input on the first loop, but successive loops produce the error I was encountering when the getline() function was in it's original position in the code.

Am I trying to utilize an array of strings in an improper fashion, or is the getline() function not being used properly?


So today is your lucky day, because usually I don't do homework. Your problem is that you need to ignore the return of your cin.

So this should solve your problem but it is not tested:

struct PanCakeEater
{
    int pancakeEaten;
    std::string name;
};
bool PanCakeSort(PanCakeEater const& eater1, PanCakeEater const& eater2)
{
    return eater1.pancakeEaten < eater2.pancakeEaten;
}

int main()
{
    std::vector<PanCakeEater> eaters;
    const size_t numberOfEaters = 3;
    for(size_t i = 0; i < numberOfEaters; ++i)
    {
        PanCakeEater p;
        std::cout << "Please enter an amount of pancakes eaten by consumer number " << i << "." << std::endl;
        std::cin >> p.pancakeEaten;
        std::cin.ignore(); // ignore the \n
        std::cout << "Please enter the name of the person who ate that amount of pancakes." << std::endl;
        getline(std::cin, p.name);
        eaters.push_back(p);
    }
    std::sort(eaters.begin(), eaters.end(), PanCakeSort);
    for(auto iter = eaters.begin(); iter != eaters.end(); ++iter)
    {
        std::cout << iter->name << ": " << iter->pancakeEaten << std::endl;
    }
    return 0;
}

Pancake Glutton, Pancake Glutton Write a program that asks the user to enter the number of pancakes eaten for breakfast by 10 different people (Person 1,  You could extend your program to remember the names of the pancake eaters, while you're at it. If you do, consider using a struct to store the data about a person. Oh, and remember C++ arrays start at 0. You're not using the first array element at the moment. Andy


    #include<iostream>

    using namespace std;

    int main()

    {

     int ate[10],eater[10],hold,temp;

     cout<<"\t\tEnter How Many Pancakes Did Each Person Eat?\n\n";

     for(int h=0;h<10;h++)

     {

      eater[h]=h;

     }

     for(int q=0;q<10;q++)

     {

      cout<<"Person "<<eater[q]+1<<" Ate: ";

      cin>>ate[q];

     }

     cout<<"____________________________________________\n\n"<<"\t\tOrdered  List Of Above.\n\n";

     for(int a=0;a<10;a++)

 {

  for(int b=0;b<10;b++)

  {

   if(ate[b]<ate[b+1])

   {

    hold=ate[b];

    ate[b]=ate[b+1];

    ate[b+1]=hold;

    temp=eater[b];

    eater[b]=eater[b+1];

    eater[b+1]=temp;

   }

  }

 }

 for(int w=0;w<10;w++)

 {

  cout<<"Person "<<eater[w]+1<<" Ate "<<ate[w]<<" Pancakes\n";

 }

 return 0;

}

Pancake Glutton (I prefer waffles, mysel - C++ Forum, ok, i need a little help on the pancake glutton exercise, i have posted the ok, i know the program somewhat works, but i have two questions: 2) I am new to C​++, does my code look "pretty"? is there anything i can do to  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)


Here is a simple version of it. Must be easier for some beginners to understand.

#include <iostream>
  #include <string>
  using namespace std;
  int main() {
      int y;
      cout << "How many people do you want to enter=  \n";
      cin >> y;
      string names[10];
      int pancakes[10];

      for (int i = 0; i <= y-1 ; i++) {
          cout << "enter name= ";
          cin >> names[i];
          cout << "num of pancakes= ";
          cin >> pancakes[i];
      }
      int maxEaten = pancakes[0];
      int minEaten = pancakes[0];
      string maxPer = names[0];
      string minPer = names[0];

      for (int k = 1; k < y; k++) {
          if (pancakes[0] < pancakes[k]) {
              maxEaten = pancakes[k];
              maxPer = names[k];
          }
          if (pancakes[0] > pancakes[k]) {
              minEaten = pancakes[k];
              minPer = names[k];
          }
      }


      cout << maxPer << " ate " << maxEaten << " which is the maximum." << endl;
      cout << minPer << " ate " << minEaten << " which is the minimum." << endl;

      system("pause");
}

Pancake Glutton Program in C++, 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  And I'm currently working on Pancake Glutton. you may need to fix if you do not have c++11 enabled. min = pancakes Programming; General C++ Programming


Pancake Glutton, Code, compile, and run code in 50+ programming languages: Clojure, Lua, Python 2.7, Ruby, Roy, Python, Nodejs, Go, C++, C, C#, F#, HTML, CSS, JS, Rust​,  Heat oil in a griddle over medium-low heat. Drop 1 to 2 heaped tablespoonfuls onto the griddle for each pancake. Cook until bubbles form and the edges are dry, 3 to 4 minutes. Flip and cook until browned on the other side, 2 to 3 minutes.


Pancake Glutton-2, Write a program that asks the user to enter the number of pancakes eaten for breakfast by 10 But I have serious doubts about receiving employment with C​++. How to make the Best Gluten Free Pancakes Recipe: In a large bowl, whisk together flour, baking powder, baking soda, salt and sugar. Add in eggs, milk, and vanilla extract. Mix until smooth. Heat a lightly oiled frying pan or an electric skillet over medium high heat. Pour approximately 1/4 cup cup for each pancake on to griddle.


C++ Pancake glutton, Begginer asking for help. : cpp_questions, 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  Pancake Glutton. Posted on January 29, 2014 by lorilew. This is a simple project that uses logic (if statements) and loops (for). The user inputs the number of