Assignment: Using C, Write a program to read a set of scores from a text file, c
ID: 663713 • Letter: A
Question
Assignment:
Using C, Write a program to read a set of scores from a text file, count the scores over 90, copy the scores over 90 to a new file, and print the number of scores over 90 to the monitor.
Then, make the program count and create a file for the ranges 0 to 30, 31 to 60, 61 to 90, and over 90. Print the statistics for each range at the end of the program.
Extra Details:
The name of the file to be read is "fileIn.txt" and the output files
must be named "range1.txt", "range2.txt", "range3.txt" and "range4.txt". Where the statistics are printed,
refer to them by the name of the corresponding output file. For example:
range1.txt contains X scores from 0 to 30
range2.txt contains X scores from 31 to 60
range3.txt contains X scores from 61 to 90
range4.txt contains X scores over 90
Here is my code: http://pastebin.com/ZMDztqfi
The code runs and reads the information in my fileIn.txt.
However, after running, range1.txt only contains %d for every number in that category in my fileIn.txt.
Every other text file created has the score. Why is this?
My fileIn.txt is every integer from 0 to 100 (including 100).
Explanation / Answer
The reason you get &d in place of the score is because you just made a typo (written &d instead of %d) in the line:-
if ((score >= 0)&&(score <= 30))
{
fprintf(range1, "&d ", score);
count4++;
}
It should be:-
fprintf(range1, "%d ", score);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.