[C++]Help for advanced beginners!

Junior Spellweaver
Joined
Jun 10, 2008
Messages
117
Reaction score
0
I made a quick quiz for you all to look at. Basically all it does it ask questions. You can read it over and study the code to help you understand a little bit more on basic C++ functions.

Code:
#include <iostream>
#include "string"

using namespace std;

int main(){
//variables
int correct = 0;
int incorrect = 0;
int diff;
string name;
       //introduction
   cout << "Welcome to the quiz!" << endl;
   cout << "Please enter your name:" << endl;
   cin >> name;
   //Difficulty level
   cout << "Hello " << name << ", please enter the difficulty level (1, 2, 3):" << endl;
   cin >> diff;
   //clears the screen
   system("cls");
   //Game start
   if(diff == 1){
                     //Question 1
                     cout << "Question 1:\nHow many stripes are on the American Flag?" << endl;
                     int stripes;
                     cin >> stripes;
                     if(stripes == 13)
                     {
                                //If they answered correctly then the number correct goes up.
                                cout << "Correct! Lets move to the next question." << endl;
                                correct++;
                                system("pause");
                                }else{
                                      //If they answered incorrectly then the number incorrect goes up.
                                      cout << "Sorry! Incorrect answer." << endl;
                                      incorrect++;
                                      system("pause");
                                      }
                     //Question 2
                     system("cls");
                     //Score Display
                     cout << "Correct:" << correct << "Incorrect:" << incorrect << endl;
                     cout << "Question 2:\nHow many letters are in the Alphabet?" << endl;
                     int alph;
                     cin >> alph;
                     if(alph == 26)
                     {
                             cout << "Correct! There are 26 letters in the English Alphabet" << endl;
                             correct++;
                             system("pause");
                             }else{
                                   cout << "Sorry! Incorrect answer." << endl;
                                   incorrect++;
                                   system("pause");
                                   }
                     //Question 3
                     system("cls");
                     cout << "Correct:" << correct << "Incorrect:" << incorrect << endl;
                     cout << "Final question!\nWhat is the name you input at the beginning of the quiz?" << endl;
                     string name2;
                     cin >> name2;
                     if(name2 == name){
                              cout << "Correct!" << endl;
                              correct++;
                              system("pause");
                              }else{
                                   cout << "Sorry! Incorrect answer." << endl;
                                   incorrect++;
                                   system("pause");
                                   }
                     system("cls");
                     if(correct >= 2){
                                cout << "Congratulations, you scored " << correct << " correct!" << endl;
                                system("pause");
                                }
                     else if(incorrect >= 2){
                          cout << "I'm Sorry!, you scored " << incorrect << " incorrect." << endl;
                          system("pause");
                          }
                          }else if(diff == 2){
                     cout << "Incopmlete!";
                     system("pause");
                    }else if(diff == 3){
                     cout << "Incopmlete!";
                     system("pause");
                     }
                     return 0;
                }

This DOES compile so do not worry about errors. Tell me anything you have questions with and i will answer to the best of my ability.
 
There's nothing being advanced beginner here :\ And code readability isn't that great, I'm not talking about the logic since you said not to worry about it.
 
Ok, they point of it wasn't to tell noobs how to indent their code, the point was to show basically how code can be arranged for the program to be consistent with what you want it to do. Basically, it will show people who know how to do basic C++ coding how to put it all together. I don't want to be told how to indent my code because truthfully, if you put it in a compiler it will read it fine any way. Just because the program i used indented it badly does not mean that it is unreadable
 
So are you. You don't need help so why do you bother looking? Have you even tested it? Does it work? If it does then get out. You don't need it.
I bother looking for much the same reason you bother making an example code like this. It's fun for me...

I don't need to test it to see it probably works like intended, and its functionality never was a problem to me, anyway. When you're given feedback, try and appreciate it instead of shrugging it off with "it works so I don't care". There are other valuable things to building software besides raw functionality.

I think I've made my point clear already and I don't want to flood your thread any further, but I would very much like to hear in what perspective I appear hopeless to you, so please do reply as PM.
 
I'm not going to PM you. I have had a good day today and i really don't want to ruin it with petty responses that will get me us no where in life. If i do PM you, it will be for personal help and that's all. Sorry for acting like an ass.
 
Back