u used
when u didnt even specify what value Correct is.Code:int Correct;
How could u print Correct on the screen when u didnt even assign it a value?
Im trying to make a program that tells you the grade when given the number of questions and the number of questions correct.
When I try to run it, it says "The variable 'Correct' is being used without being initialized."
Here is the code
How do i fix this?Code:#include "stdafx.h" #include <iostream> #include <math.h> #include <stdio.h> using namespace std; void main () { int Questions; int Correct; cout << "Assignment Grader\n\n"; cout << "Enter the number of questions, hit enter/return, enter the amount of questions correct, and hit enter\n\n"; for (;;) { cout << "Questions: "; cin >> Questions; cout << "\n"; cout << "Correct: "; cout << Correct; cout << "\n"; cout << "Grade: "; cout << (Correct/Questions)*100; cout << "%\n\n\n\n\n"; } char f; cin >> f; }
u used
when u didnt even specify what value Correct is.Code:int Correct;
How could u print Correct on the screen when u didnt even assign it a value?
This is confusing.... Why didn't you ask for user input for correct...?
~
And why are you using extra headers that aren't needed....
"If the world hates you, keep in mind that it hated me first." John 15:18
Yea but i cant assign correct a value because the user has to enter how many the person got correct.
And i just started learning C++ yesterday so idk what i will and wont need. Can some1 just tell me how to fix it
you need to add a
~Code:cin >> Correct;
currently Correct equals 0 and you're dividing by 0 that's a big no no, I don't know if Windows does it but Linux would deliver you a fault error before run.
"If the world hates you, keep in mind that it hated me first." John 15:18
Oh snap. That's what i meant to put instead of
tyCode:cout << Correct;
Now when i tested with questions as 17 and correct as 15 it says 0% -.-
What's wrong now?
Use floats (doubles) instead of int.
~
You might want to truncate the results to only one or two significant figures (17.12343 compared to 17.12). For learning how to do that with the cout class, msdn is your friend. There's never a time when you wont be referencing from msdn or some other place so there's no shame in doing that.
"If the world hates you, keep in mind that it hated me first." John 15:18
Melodia (04-11-2010)
K. ty. It works fine now. And do you code hacks because i need some1 to teach me. Reading tuts confuses me most of the time -.-
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
I'm just glad we got a newbie who didn't try to fake anything.
~
Keep tryin' lil' fella =D
"If the world hates you, keep in mind that it hated me first." John 15:18
What do I need to learn?
And yea i didnt fake anything. Lol. Im not much of a noob. xD
Although im terrible in warrock without muh h4x0rz
In my opinion, the best way to learn to program is to get a book at the library or buy one somewhere. What you are trying to do with this program is simple math. Take the number of questions that are incorrect and divide by the total number of questions and then multiply by 100. It's been a long time since I've done any programming, so I'm not too sure.
float total;
float incorrect;
float score;
float multiplier = 100;
score = (incorrect / total) * multiplier;
cout <<"percent correct: " score;
Like I said, it's been like 6 months since I've even touched a c++ compiler, so maybe why06 can explain it better.
Last edited by t7ancients; 04-13-2010 at 12:58 PM.
Yea i already got it working.
I had ainstead of aCode:cout << correct;It was a stupid mistakeCode:cin >> correct;