Forum Settings
Forums
New
Nov 1, 2014 10:02 PM
#1

Offline
Jan 2009
92509
im a computer science graduate but i forgot all about programming now, if you do not get any help on this thread then i suggest you go to codeguru or even stackoverflow

http://forums.codeguru.com/forum.php
http://stackoverflow.com/
Nov 1, 2014 10:36 PM
#2
Offline
Apr 2013
12542
Why not
for (i++;i <20; i++){

cin >> user_answers [ i ] ;
If ( Answers [ i ] == user_answers [ i ] )
Count_of_Correct++;

}
worldeditor11Nov 1, 2014 10:41 PM
Nov 2, 2014 7:25 PM
#3

Offline
Feb 2013
6196
Oh programming homework!

I didn't notice anything wrong with your code... looks like it should work (or close to it).

What is the program output?

edit

Heck... I have VS on here... debugger told me you forgot to initialize "wrong" and "correct" variables.
Your input loop was also off by one because you did x++ way too soon. Here's what I changed (dropped to 2 questions for speed testing):
int x = 0, wrong = 0, correct = 0;

while(x < 2)
{
  bool valid = false;
  while(!valid)
  {
    cout << "Enter your answer for question " << x + 1 << endl;
    cin >> user_answers[x];

    if(user_answers[x] == 'A'
      || user_answers[x] == 'B'
      || user_answers[x] == 'C'
      || user_answers[x] == 'D')
    {
      valid = true;
    }
    else
    {
      cout << "Invalid input.  Enter only: A, B, C, or D.  Try again." << endl;
    }
  }

  x++;
}
Notice how I get the input and check it after... makes the code a bit easier and you don't have to deal with duplicate cin's.

Output (dropped it to 2 questions):
Enter your answer for question 1
z
Invalid input.  Enter only: A, B, C, or D.  Try again.
Enter your answer for question 1
B
Enter your answer for question 2
A
Answer 2 Wrong
Results (minimum 15 correct to pass):
You got 1 correct.
You missed 1
You've failed.
BurntJellyNov 2, 2014 7:46 PM
Nov 2, 2014 8:01 PM
#4

Offline
Aug 2013
1336
lol, learning computer science C++ from MAL.

Actually pretty legit, I've gained some knowledge while working on my list.

More topics from this board

» Pokemon : Which legendary pokemon have you randomly came across without looking up their location?

Thy-Veseveia - Apr 9

4 by DreamWindow »»
2 hours ago

» Gacha Survey ( 1 2 )

Shizuna - Apr 11

57 by DreamingBeats »»
3 hours ago

» Looking for more Anime Pixel Games

Astachanna - Apr 4

12 by Astachanna »»
7 hours ago

» Last game you purchased ( 1 2 3 4 5 ... Last Page )

Completely_Numb - Mar 15, 2014

525 by Timeline_man »»
8 hours ago

» Stellar Blade Preview: Sekiro Meets NieR: Automata?

deg - Feb 1

28 by Shizuna »»
10 hours ago
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login