hello ppl
im new to C++
i was making a small newbie math quiz..
and was wandering how can i make it that at the end it says how much u got out of 10 or watever
this is my code so far

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
  int Answer,toll,drive,bath;
  {    cout<< "5+5=";
       cin>> Answer;
 
       if (Answer ==10)
        { 
       cout<< "correct!\n";
         }
       else 
 
       cout<< "Incorrect\n"<< "Correct answer is 10\n";
  
  }
  system("pause");
  {    system("cls");
       cout<< "5x25=";
       cin>> toll;
 
       if (toll ==125)
        { 
       cout<< "Well Done!\n";
         }
       else 
 
       cout<< "Wrong!\n"<< "Correct answer is 125\n";
  }
  system("pause");
  {
       system("cls");
       cout<< "12x13=";
       cin>> drive;
 
       if (drive ==156)
        { 
       cout<< "Good Work!\n";
         }
       else 
 
       cout<< "Not Right!\n"<< "Correct answer is 156\n";
       system("pause");
   }
       system("cls");
       cout<< "12+13x(13/6.5)=";
       cin>> bath;
 
       if (bath ==50)
        { 
       cout<< "Good Work!\n";
         }
       else 
 
       cout<< "Wrong!\n"<<"Correct answer is 50\n";
       system("pause");
    {
              system("cls");
              if (Answer==10&&toll==125&&drive==156&&bath==50)
                 { cout<< "\nGood Work\n 4/4 Correct\n";}
                 else
                 cout<< "Not 100%\n";
                 }
 
 system("pause\n");
 return 0;
}

i got it so it only says if u got all of them right or it says "not 100%"... also if i am doing somthing wrong please say so .
much appreciation :P

Try to avoid, system( "pause" ); if you can. It works only for windows, and it needlessly calls a DOS/Windows command. Try cin.get(); instead. Another thing you are making blocks for no reason. Making the impression each block is a branch, and after that your program will behave differently. Well it wont, your program is a sequence of instructions( as any program ), you are only making "checks". You need blocks when you are making actual branches, and you have a lot of instructions in a branch. So don't let to fool yourself by making that impression. :)

Try to make it simple, make it easy to read, but this really depends on your taste.

int main()
{
    int Answer, toll, drive, bath;
    cout << "5 + 5 = ";
    cin >> Answer;
    
    if( Answer == 10 ) cout << "correct!\n";
    else cout << "Incorrect\n" << "Correct answer is 10\n";

If you want to give back the percentage of the correct answers, you have to know how many good answers you have in the end. The easiest way is to create an int variable with 0. And then increment it each time, when the user gives the correct answer. You have 4 questions each worths 25%, the rest is easy. Or you can actually calculate it (good answers / questions) * 100.

int good = 0;
    
    if( Answer == 10 )
    {
        cout<< "correct!\n";
        good++;
    }

Always make sure you initialized the variable, or you will increase some strange value in the memory. Uninitialized variables have values too! Search for post/preincrement.
Reasons to avoid system("pause");

Yet another tip:
Now try to invent a function (with two parameters: the question and the right answer) which can ask user, check the answer then return 1 on success or 0 on failure. Sum all returned values then print the test result...

Thanks BevoX everything is good i have fixed it up but I still don’t get the using cin.get() instead of system("pause") if anyone could put it in a e.g. would help. ArkM im not too shore of using functions, parameters it’s only like the second day that i have dl a compiler and started to practice. If anyone know a site where functions are explained good or can explain them for me would we great.:)
By the way I got Dev C++
if anyone knows of a better one please say so

hello ppl
im new to C++
i was making a small newbie math quiz..
and was wandering how can i make it that at the end it says how much u got out of 10 or watever

Make use of a variable 'points' for instance and increase it by one every time a right answer has been given ...

This information about variables might be helpful ...

By the way I got Dev C++
if anyone knows of a better one please say so

I would use Code::Blocks instead (reason: Dev-C++ isn't being developed anymore (there are still some bugs in it), Code::Blocks is more advanced and up-to-date ...), but since you're a newbie programmer Dev-C++ will still fit your needs ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.