Histogram

Hi,

I have just completed this small cafeteria program. I do have a few issues I hope you can help me with. Here are my questions.

1) On the output I wish to have the numbers as well as the asterisks representation of that number displayed. For example.

1 = *, 5 = *****, etc.

Thank you in advance for any help that can be offered

This is my code



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Date - 12/11/2011
// this program will rate cafeteria food.

#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;
}
Last edited on
try this you can't void main it must be an int and if you go to the format section when posting you will see a <> button that generates and which you should encase your code in
sorry it is [bold][/bold] and it is const var_type not var_type const
dangit just use the "blocks that appear when you click the <> button
Topic archived. No new replies allowed.