Survey

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. Thanks for any help.
_______________________________________________________________________________

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
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <iomanip>

using namespace std;
//void stars(int response);

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";	
	for(int response = 0; response < SIZE; response++)
	{
		cout<< "*";
	}
			cout << 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;
}
//void stars(int response)
//{
//for( response =0; response > 0; response--)  // cout first line of *
//	{
//		cout << '*';
//	}
//	cout << endl;
//	return;
//} 
Last edited on
1
2
3
4
5
6
7
8
9
//void stars(int response)
//{
//for( response =0; response > 0; response--)  // cout first line of *
//	{
//		cout << '*';
//	}
//	cout << endl;
//	return;
//}  


If this is the loop your trying to figure out. Then I believe the reason it isn't working is because you are initiating response to 0, which will not execute the loop because your testing if response > 0 which it isn't.

You could solve this by simply editing your response start....

EX:

1
2
3
4
5
6
7
8
9
//void stars(int response)
//{
//for( response; response > 0; response--)  // cout first line of *
//	{
//		cout << '*';
//	}
//	cout << endl;
//	return;
//}  

This solution will only work however if your input is greater than zero. If you want to include zero in the ratings you will have to change your test to response >= 0.
This should solve your problem. Also if you want to make it like your other for loops and increment rather than decrement you could do this

1
2
3
4
5
6
7
8
9
//void stars(int response)
//{
//for( int i = 0; i < response; i++)  // cout first line of *
//	{
//		cout << '*';
//	}
//	cout << endl;
//	return;
//}  


All depends on what you like =]

Hope you found this helpful if not sorry I've only been coding in C++ for about 6 months now
Thank you for your insight, however what i really need this application to do at this time is...for every rating the user inputs, I should get an asterisk in the frequency field indicating that entry

for example, if I enter a rating of 5 three times and 8 twice it should look like this on the output. The remainder should only indicate the amount of individual entries made.

Rating Frequency
-------------------
1
2
3
4
5 ***
6
7
8 **
9
10
Topic archived. No new replies allowed.