What the fuck am I doing wrong?
Posting an image instead of a pastebin
You're using C++
What's your error?
>>51397603
This desu
>>51397578
http://pastebin.com/VTSYtaSv
>>51397625
Warning 1 warning C4101: 'scores' : unreferenced local variable
I am new to c++ and programming in general, this is like moonspeak to me.
might be the missing break statements in the cases
You're getting the warning because you haven't referenced (used) the variable 'scores'.
If you aren't going to use int scores[5];. then comment it out and that will go away.
This isn't an "error". It's just a compiler warning.
>>51397640
You're not usingscoresyou doof
>>51397554
>>51397643
As he stated, you also should have the 'break;' statement inside the empty cases.
>>51397669
Do I need the int scores[5];? 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)
>>51397689
how do I fix that?
>>51397689
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.
>>51397689
>>51397643
Do C++ needs breaks in every case? Have you read the code?
>>51397689
Nvm, I understand.
>>51397697
You don't need "scores". Nuke it.
>>51397715
I've always used them. But I've never used switch statements anyway.
>>51397697
You have to actually use it. You're currently not doing so.
>>51397729
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.
http://pastebin.com/sWmN96tD
>>51397754
How would I go about adding it into my code? that's the part that confused me, sorry.
Can you tell us why it's not building the program?
>>51397755
>>51397823
I might be retarded. It's not giving me an output now.
>>51397771
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.
>>51397823
>>51397921
Fixed it, this is what it displays.
I'll add the break; to the lines
http://pastebin.com/Prdr2eUH
shouldn't
#include <tchar.h>
be
#include "tchar.h"
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
>>51398071
he casts it as an int so (testScore/10.0) evaluates to a whole number
>>51398071
why do you use " " instead of < >?
>>51397939
The new breaks are not needed. You have a problem with your environment. Google those missing libraries.
>>51398101
<> denotes a "library" copy (meaning it grabs them from library directories)
"" denotes a local copy" (meaning it grabs them from usually the proj/solution directory)
>>51398108
>>51398108
ty anon
>>51398108
Actually, it seems those are expected warning messages.
Do the program works?
>>51398094
It should remain an int though since test score and 10 are both ints. the static cast is unnecessary.
>>51398143
Oh, I didn't notice testScore was an int, so yea, you are right, there is no need for the static_cast<>
>>51398143
it broke the code passed line 45 after I took out my static_cast.
>>51398163
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.
>>51398183
Ignore my picture, I fixed it.
>>51398163
Still, in regards to my int testScore, is that fine to use when pulling the numbers from another file?
>>51398205
yea, just make sure you format your data correctly
>>51398237
cool.
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.
Looks like you never open outfile. You just declare it as an ofstream and start writing to it. Pretty sure that's a bad idea, at the very least you'll never produce any output.
>>51398205
Are the numbers your pulling out ints?
yes.
Are the numbers your pulling out doubles or larger?
no.
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.
paste your code in pastebin
>>51398280
wait, where do I open my outfile, then. Do I need an outfile if I'm only looking to display the data, not make a new file for it?
>>51398319
http://pastebin.com/PtD21X4n
>>51398336
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;
>>51398456
this.
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
class average:80.17
>>51398456
I don't know much, I'm new to this.
can I keep my infile without keeping my outfile? or can I outfile and then display the outfile with something?
>>51398505
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;
>>51398529
how do I remove the outfile << before my while (infile) statement without destroying my code?
I don't know which spots I can exclude cause now I'm getting a LINK error
>>1398505
>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).
>>51398584
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.
heres your code, i didnt get any compile errors with VS
http://pastebin.com/ixd8dRvk
>>51398620
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.
>>51398620
thats all iomanip stuff
http://www.cplusplus.com/reference/iomanip/
>>51398700
>because I think the setw/setprecision stuff is a pain
Pain in the fucking ass is right.
>>51398626
ily
>>51398701
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.
>>51398726
Why is it a pain?
Also, thank you anons for all your help
>>51398736
>Why is it a pain?
Don't worry, you'll experience it.
>>51398816
I need an adult