Results 1 to 14 of 14
  1. #1
    killashoota1's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    37
    Reputation
    10
    Thanks
    4

    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?

  2. #2
    scimmyboy's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Location
    https://mpgh.net MPGHCash: $442,596,199
    Posts
    5,645
    Reputation
    26
    Thanks
    896
    My Mood
    Happy
    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?

  3. #3
    Arhk's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Engineering
    Posts
    3,618
    Reputation
    35
    Thanks
    217
    My Mood
    Amused
    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

  4. #4
    killashoota1's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    37
    Reputation
    10
    Thanks
    4
    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

  5. #5
    Arhk's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Engineering
    Posts
    3,618
    Reputation
    35
    Thanks
    217
    My Mood
    Amused
    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

  6. #6
    killashoota1's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    37
    Reputation
    10
    Thanks
    4
    Oh snap. That's what i meant to put instead of
    Code:
    cout << Correct;
    ty

  7. #7
    killashoota1's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    37
    Reputation
    10
    Thanks
    4
    Now when i tested with questions as 17 and correct as 15 it says 0% -.-
    What's wrong now?

  8. #8
    Arhk's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Engineering
    Posts
    3,618
    Reputation
    35
    Thanks
    217
    My Mood
    Amused
    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

  9. The Following User Says Thank You to Arhk For This Useful Post:

    Melodia (04-11-2010)

  10. #9
    killashoota1's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    37
    Reputation
    10
    Thanks
    4
    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 -.-

  11. #10
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    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++.

    "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

  12. #11
    Arhk's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Engineering
    Posts
    3,618
    Reputation
    35
    Thanks
    217
    My Mood
    Amused
    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

  13. #12
    killashoota1's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    37
    Reputation
    10
    Thanks
    4
    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

  14. #13
    t7ancients's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    New York
    Posts
    381
    Reputation
    28
    Thanks
    68
    My Mood
    Twisted
    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.

  15. #14
    killashoota1's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    37
    Reputation
    10
    Thanks
    4
    Yea i already got it working.
    I had a
    Code:
    cout << correct;
    instead of a
    Code:
     cin >> correct;
    It was a stupid mistake

Similar Threads

  1. [Help] What is wrong with this code!
    By killer660 in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 14
    Last Post: 08-01-2011, 09:55 AM
  2. [Help] What is wrong with this code?
    By IGNITE09178 in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 15
    Last Post: 07-01-2011, 03:59 AM
  3. Bad Syntax - What is wrong with this code?
    By HACKINGPIE in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 5
    Last Post: 01-19-2011, 12:12 AM
  4. What is wrong with this code?
    By t7ancients in forum C++/C Programming
    Replies: 10
    Last Post: 10-19-2009, 01:58 PM
  5. Whats wrong with my code? =(
    By SadisticGrin in forum C++/C Programming
    Replies: 13
    Last Post: 08-03-2007, 11:39 AM