PDA

View Full Version : An array


Crispy
Oct 11, 2007, 08:52 AM
How many ratings do you wish to enter? 10
Rating #1: 9
Rating #2: 5
Rating #3: 9
Rating #4: 2
Rating #5: 11
Invalid entry, score must be in range of 1 and 10; try again.
Rating #5: -1
Invalid entry, score must be in range of 1 and 10; try again.
Rating #5: 8
Rating #6: 8
Rating #7: 9
Rating #8: 7
Rating #9: 9
Rating #10: 8
Here are the results:

10 ratings entered
Rating Frequency Percentage
===============================
1 0 0%
-------------------------------
2 1 10%
-------------------------------
3 0 0%
-------------------------------
4 0 0%
-------------------------------
5 1 10%
-------------------------------
6 0 0%
-------------------------------
7 1 10%
-------------------------------
8 3 30%
-------------------------------
9 4 40%
-------------------------------
10 0 0%
-------------------------------

This is how this program should look like. Can some one tell me how to get the part of frequency and percentage. I am having trouble coming with a solution. This is what I have so far #include <iostream>
#include <string>
#include <iomanip>
using namespace std;

const int Num_Rating = 10;
void main(void)
{
auto int userArray[Num_Rating];
auto int index;
auto int Frequency;
auto int Percentage;


cout << "How many ratings do you wish to enter? " << Num_Rating << endl;

for((index = 0); index < Num_Rating; ++index)
{
cout << "Rating #" << index << ":";
cin >> userArray[index];
}
if( index > Num_Rating)
{
cout << "Invalid entry, score must be in range of 1 to 10, try
again.";
cout << "Rating #" << index << ":";
cin >> userArray[index];

}
Frequency =
Percentage =
cout << "Here are the results:\n\n";
cout << "Rating\t\tFrequency\t\tPercentage" << endl;
cout << "=================================" << endl;
cout << "1\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "2\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "3\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "4\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "5\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "6\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "7\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "8\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "9\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;
cout << "10\t\t" << Frequency << Percentage << endl;
cout << "---------------------------------" << endl;

} // end of "main"
PLEASE HELP ME THANK YOU

asterisk_man
Oct 15, 2007, 10:12 AM
Is your problem the format for the frequency and percentage?
Have you tried:
Cout << "1\t" << Frequency << "\t" << Percentage << endl;