I tried several times to solve this aproblem but I can not.
The problem is:
------------------------------------------------------
Write a C++ program that reads total marks of at most 50 students from an input file called scores.txt. The total marks are whole numbers out of 100 and are sorted in the input file by increasing order of ID. The following is a sample input file.
1. Count the percentage of students in each grade category and display these as whole percentages (rounded to two digits) as shown in the sample output below. You also need to count the percentage of invalid score entries.
2. Find the grade corresponding to each student according to the following table and write the grades in reverse order of ID to an output file called grades.txt
Between 90 and 100 (inclusive) A
Between 81 and 89 (inclusive) B
Between 71 and 80 (inclusive) C
Between 60 and 70 (inclusive) D
Between 0 and 59 (inclusive) F
Less than 0 or more than 100 ERROR
The following is the output of the program corresponding to the sample input:
Grade Percentage
A 33%
B 17%
C 17%
D 17%
F 0%
Invalid 17%
Contents of output file:
ID Grade
66666 ERROR
55555 A
44444 C
33333 D
22222 B
11111 A
When you enter code for a something you want answered please put it in the form [code]...enter code [/code] this way it highlights certain areas such as your function, classes, etc makes it easier to read. If you want to do it the lazier way just press the <> key after highlighing the code. From what I can gather from your code that you do have in the forum though is very disorganized remember for mat when writing IE
1 2 3 4 5 6 7 8
{
cout << "Hello from main.\n";
for ( int count = 0; count < 5; count++ )
displayMessage(); //Call displayMessage
cout << "Back in function main again.\n"'
system ("PAUSED");
return EXIT_SUCCESS;
}
noticed that it is tabbed indicating the opening and closing of a part of your program.
also not sure why your while has for loop inside of it you might get an infinite loop unless you have some means of stopping that loop which means
1 2 3 4 5 6 7
int count = 0
while (Scores_File < 5)
{
for (n=0; n < 50; n++)
count++;
}
//count keeps incementing till it reaches 4 remember 0 is counted by the compiler.
You can do a loop in a loop but you need to make sure you have a condition that needs to be met or else you will create an infinite loop and your program will keep going creating a logic error
if the number of students unknown and i need from the compiler to read all students IDs and marks. then store them in an array. how is the array declared?
In your post on your first one it said a max of 100 to read from the data file. What I am showing you is not going to read from the data file that he gives you I assumbe but I will show you how to set up yours the only difference is besides reading the data file is you have to change the number 5 to 100 this will give you up to 100 students
Are you reading data from a file or writing data to a text file?
If reading you will need to read data from the file and store it to an array. The processes is straightforward, and in most cases is best done with a loop like
int main()
{
constint NUM_STUDENT = 5; // change to 100 students
int studentIDS[NUM_STUDENT];
constint PERC_STUDENT = 5; //change to 100 students
double percentNum[PERC_STUDENT];
// Open Data File
datafile.open(grades.txt);
if (!datafile)
cout << "Error opening data file\n"else
{ // Input student grades
for(count = 0; count < NUM_STUDENT; count++)
datafile >> studentIDS[count];
datafile.close();
//rest can be finished with what I alread gave you.
{
Each iteration of the loop reads an item from the file and stores it in an array element.