What's wrong with ths code?

Posts 1–14 of 14 · Page 1 of 1
What's wrong with ths code?
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

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;
	
}
How do i fix this?
u used
Code:
int Correct;
when u didnt even specify what value Correct is.

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....
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.
Oh snap. That's what i meant to put instead of
Code:
cout << Correct;
ty
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.
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 -.-
Quote Originally Posted by killashoota1 View Post
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 -.-
I can see why... =/

Your not ready to learn how to hack. Atleast not with C++. You can use trainers and memory searchers and learn how programs work, but if you really want to hack some big time games you need to learn C++.
I'm just glad we got a newbie who didn't try to fake anything.
~
Keep tryin' lil' fella =D
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.
Yea i already got it working.
I had a
Code:
cout << correct;
instead of a
Code:
 cin >> correct;
It was a stupid mistake
Posts 1–14 of 14 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?