You're getting the warning because you haven't referenced (used) the variable 'scores'.
If you aren't going to use int scores;. then comment it out and that will go away.
This isn't an "error". It's just a compiler warning.
Do I need the int scores;? This is my endgoal:
Write a program that reads from a file (with variable number of records) student names and the grades for 2 tests and 2 assignments (the points are between 0 and 100) (format: First Last Test1 Test2 Assignment1 Assingment2) and determines and outputs for each student the average score for the 2 tests (column Tests Average)1, average score for the 2 assignments (column Assignments Average)2, the overall total points for all tests and assignments (column Total Points), the numeric grade (column Numeric Grade)3 (between 0 and 100) and the letter grade (column Letter Grade)4. The program should also compute and output the number of students (row Number), the minimum numeric grade (row Minimum), maximum numeric grade (row Maximum) and average numeric grade (row Average) among all students and displays them with 2 decimals. Display the output in the exact format shown below (use 2 decimals for floating-point numbers and the columns and alignment suggested bellow)
how do I fix that?
Not OP but this way all the empty statements fall through and give an F for the score. Adding breaks would require repeating the code for setting the grade to F, and as such would be unnecessary.
OP here, I changed a few things, nuked the scores.
Here is the datafile that I'm importing, my visual studio won't build my program for some reason, I have files that are corrupt lol.
you dont need breaks in every case. But if you dont, the code will keep reading until it encounters a break (including other cases code); for this reason break is only mandatory after the default case.
also for your switch statement:
switch (static_cast<int> (testScore / 10)
what are you trying to do? If you want that to be a double simply have
switch (testScore / 10.0)
the 10.0 makes the equation return a double
Also I think the while (infile) loop on line 38 might be an infinite loop, it should probably be and if statement instead
it broke the code passed line 45 after I took out my static_cast.
I only made testScore an int because I kept getting an error when trying to pull the testScore from another file. I don't know if it is correct or not.
Does anyone have Visual Studio that can run this code? I can't find a download to test the results and I need a screen cap of the display table just to make sure it's working.
Are the numbers your pulling out ints?
Are the numbers your pulling out doubles or larger?
If you expect to be reading doubles or longs or what ever from a file then declare a variable that can handle what ever you can expect to pull out (such as double testScore).
You can then use the static caste to convert to int if that's the case.
What you're doing now is like this (which is bad becuse the "Something or other" will never go anywhere):ofstream outfile;
outfile << "Something or other" << endl;
To make the "Something or other" go to the file output.txt, you would do:ofstream outfile ("output.txt");
outfile << "Something or other" << endl;
If you just want the "Something or other" to be displayed on the screen, you could use cout (pretty sure you know this, since you use it elsewhere in the program):cout << "Something or other" << endl;
if you only want to display to the screen dont do anything involving output.
Also this is the output of your program:
John Adams 90
70 95 80 B
Mary B 75 C
90 100 90 C
Abdul C 55 F
80 80 80 B
Mark D 95 B
85 100 85 B
Carrie E 80 B
100 80 100 A
Hung F 55 F
90 100 90 F
Lana G 85 B
90 90 90 B
George H 35 F
60 60 80 B
Tyrone I 60 D
60 60 80 B
Rajiv J 65 D
40 70 60 D
Gabriela K 90 D
85 90 90 D
Randy L 95 D
80 85 90 D
Andrea M 75 C
80 85 80 B
Irina N 100 A
95 100 90 A
Jose O 85 B
90 90 80 B
keep the infile.
you dont need an outfile at all if you just want to display to the screen. thats like walking upstairs downstairs then upstairs to go to your room. Just use
cout << "All this will be outputed to the screen" << endl;
>can I keep my infile without keeping my outfile?
Yes, you can just leave the infile stuff as it is, and instead of using outfile to display your results, you can just use cout.
>or can I outfile and then display the outfile with something?
You could do that too, but it's more complicated and probably not necessary (unless you're required to write the output to a new file).
Nope, not required. Now, how do I go about lining up my code to this table? I didn't really learn how to place things using text yet, I made an attempt here but it's a poor one.
Pic related, it's my end-goal.
Ugh, personally I would use printf for output like this, because I think the setw/setprecision stuff is a pain. But since this looks like a C++ assignment, I guess you're expected to use C++ things instead of printf (which is a C thing, though still usable in C++).
Anyway, I think you're on the right track with the setw/setprecision stuff. You'll just need to mess around with it until you get the output you're looking for.
I have a lot of it already set to cout but since my VS isn't letting me view my cout statements, I am just swinging for the fences.
Why is it a pain?
Also, thank you anons for all your help