Have been attempting a very silly exercise concerning arrays and pancakes.
Just trying to get the basics of my array ordering to work. I was so sure that this would work to print out the pancake numbers in descending order. It looks good to me, but doesn't print out a thing.
Have been working on it long enough now to know when to ask for a hint. Here is the code:
#include <algorithm> //for swap function
#include <iostream>
#include <string>
#include <limits>
usingnamespace std;
int main ()
{
int array [10]; //the 10 peoples pankake amounts
int smallest_spot; //variable for smallest position
int start_place =0; //variable for start place
int current_place; //variable for current location in the array
int person =1; //variable for which customer
int x;
cout << "How many pancakes did person 1 eat?" << endl;
while ((cin >> array[start_place]) && person!=10) //puts the info into
{ //the array
person++;
start_place++;
cout << "How many pancakes did person " << person << " eat? \n";
}
// step through the array
for (start_place =0; start_place <10; start_place++)
{
smallest_spot = start_place; // initiates position 0 as smallest spot
for (current_place = start_place +1; current_place < 10; current_place ++)
{
if (array[current_place] < array[smallest_spot])
smallest_spot = current_place;
}
swap (array[start_place], array[smallest_spot]);
}
for (x=9; x==0; x--)
{
cout << array[x] <<endl;
}
return 0;
}
I'm probably too tired to spot the error. Any suggestions please, I'm turning in for the night. Will report back tomorrow - many thanks in advance,