Hi,
I have just completed this small cafeteria program. I do have an issue I hope you can advise me with. Here is my question.
1) On the // Display the contents of the array output I wish to have the numbers as well as the asterisks representation of that number displayed. For example.
1 = *, 5 = *****, etc.
I already have a for loop there, but it represents the "Rating" portion, and I need one to represent the "Frequency" in "*".
I was thinking along the lines of:
for(response = 0; response > SIZE; response++)
{
cout <<"*";
}
cout endl;
return;
however, it doesn't work or I can't code it just right.
_________________________________________________________________________________________
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
const int SIZE = 5;
double response[SIZE] = {0};
double responseTotal = 0,
responseAverage = 0,
responseHigh = 0,
responseLow = 0;
system("color 1F");
cout <<"\n\t\t***********************************"
<<"\n\t\t* Cafeteria Food Survey *"
<<"\n\t\t***********************************"
<<endl
<<"\n\n" << " " <<"Enter a rating between 1 and 10: 1=AWFUL 10=EXCELLENT"
<<endl
<<endl;
for(int index = 0; index < SIZE; index++)
{
cout<<"\n" << " " << "Rate Cafeteria Food (scale 1 to 10): ";
cin >> response[index];
while(response[index] <= 0 || response[index] > 10)
{
cout <<"\n" << " " <<"\a\a\aError: Specify a number within a valid range. ";
cin >> response[index];
}
}
// Dispaly the contents of the array
system("color 2F");
cout <<"\n" <<" "<<" Rating:" << " "<<" Frequency:\n\n";
for(int index = 0; index < SIZE; index++)
{
cout <<" " << response[index]; cout <<"\t\t" <<'*' << endl;
}
// Display Ratings Average
for(int index = 0; index < SIZE; index++)
responseTotal += response[index];
responseAverage = responseTotal/SIZE;
cout <<"\n" << " " << "The Ratings average is: " << responseAverage;
// Display the highest rating
responseHigh = response[0];
for(int index = 0; index < SIZE; index++)
if (response[index] > responseHigh)
{
responseHigh = response[index];
}
cout <<"\n" <<" " <<"The Highest rating is: " << responseHigh;
// Dispaly the lowest rating
responseLow = response[0];
for(int index = 0; index < SIZE; index++)
if (response[index] < responseLow)
{
responseLow = response[index];
}
cout <<"\n" << " " <<"The Lowest rating is: " << responseLow;
cout << endl << endl;
return;
}