Friday, 19 March 2021

Simple Quiz Game with the Help of C/C++

Beginners Projects




Concepts of C++ used in this is:
1) Basic C++ concepts (cout, cin, endl, headerfiles, goto....)
2) Switch Case, if else, nested if else, loops
3) Predefine and User define functions
4) Array
5) File Handling

Full code and Downloadable pdf is also available below:
#include<iostream>
#include<conio.h>
#include<string>
#include<fstream>
using namespace std;

void funHelp()
{

}

int main()
{
    system("color 0A");
    int count=0;
    string playerName;
    mainScreen:
    cout<<"\n\n-----------------------------------------";
    cout<<"\n          WELCOME TO CODE TANTRA\n ";
    cout<<"              QUIZ GAME\n";
    cout<<"-----------------------------------------\n";
    cout<<"\n                MENU                     \n";
    cout<<"1. Play Game\t 2. View Score\t 3. Exit\n4. Help\t\t 5. Reset\n\n";

    int choice;
    cout<<"Choose any Key: ";
    cin>>choice;
    if(choice==4)
    {
        system("cls");
        //funHelp();
        cout<<"\t>> This Game contains 10 Questions\n";
        cout<<"\t>> Each questions contains 1 Points\n";
        cout<<"\t>> If user gives minimum 5 correct answer than\n";
        cout<<"\t\t  he/she will WIN this game\n";
        cout<<"\t   *******Good Luck*****";
        getch();
        goto mainScreen;
        int a;
        cin>>a;
        goto mainScreen;
    }
    else if(choice==3)
    {
        exit(1);
    }
    else if(choice==1)
    {
        system("cls");
        cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\tEnter your name: ";
       // string playerName;
        cin>>playerName;
        system("cls");
        cout<<"\n\n\n\n-------------WELCOME TO CODETANTRA QUIZ GAME-----------\n";
        cout<<"\tHere are some TIPs for playing this game\n";
        cout<<"\t>> There are total 10 questions in this game\n";
        cout<<"\t>> Each questions comes one after one\n";
        cout<<"\t>> No deduction of points if given answer is wrong\n";
        cout<<"\n\t>> Press Y to Enter into Game\n";
        cout<<"\t>> Press N to Leave the Game\n";
        fflush(stdin);
        if(getch()=='Y')
        {
            goto game;
        }
        else{
            system("cls");
            goto mainScreen;
        }
        game:
        system("cls");
    //count
        for(int i=1;i<=10;i++)
        {
            int var1=i;

            switch(var1)
            {
            case 1:
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ1.Which of the following is Palindrome number? ";
                cout<<"\n\nA. 123456\t\tB. 234511\nC. 123321\t\tD. None\n\n";
                if(getch()=='C')
                {
                    cout<<"Corrent!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is C";
                    getch();
                }
                break;
            case 2:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ2.Which of the following is Largest Mountain? ";
                cout<<"\n\nA. Kanchanjangha\t\tB. Mount Everest\nC. Himalayan Mountain\t\tD. None\n\n";
                if(getch()=='B')
                {
                    cout<<"Corrent!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is B";
                    getch();
                }
                break;
            case 3:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ3.Which of the following is Father of Computer? ";
                cout<<"\n\nA. Bill Gate\t\tB. Larray Page\nC. Bjarne Stroustrup\t\tD. Charles Babbage\n\n";
                if(getch()=='D')
                {
                    cout<<"Corrent!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is D";
                    getch();
                }
                break;
            case 4:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ4.What will be the Binary of 91 ? ";
                cout<<"\n\nA. 1011011\t\tB. 1110100\nC. 0010110\t\tD. 1100110\n\n";
                if(getch()=='A')
                {
                    cout<<"Correct!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is A";
                    getch();
                }
                break;
            case 5:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ5.What is the Frequency of Indian current ? ";
                cout<<"\n\nA. 90hZ\t\tB. 50hz\nC. 60hz\t\tD. None\n\n";
                if(getch()=='B')
                {
                    cout<<"Correct!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is B";
                    getch();
                }
                break;
            case 6:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ6.How is the Current Prime Minister of India ? ";
                cout<<"\n\nA. Ram Nath Kovind\t\tB. Jawaharlal Nehru\nC. Manmohan singh\t\tD. Narander Modi\n\n";
                if(getch()=='D')
                {
                    cout<<"Correct!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is D";
                    getch();
                }
                break;
            case 7:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ7.Chemical Formula of Copper Sulphate is ";
                cout<<"\n\nA. CuSO4\t\tB. HCl\nC. Cu2O\t\tD. NaCl\n\n";
                if(getch()=='A')
                {
                    cout<<"Corrent!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is A";
                    getch();
                }
                break;
            case 8:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ8.What will be 1's Compliment of 1011100? ";
                cout<<"\n\nA. 1011100\t\tB. 1100110\nC. 0100011\t\tD. 0111100\n\n";
                if(getch()=='C')
                {
                    cout<<"Correct!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is C";
                    getch();
                }
                break;
            case 9:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ9.Find the Factorial of 7? ";
                cout<<"\n\nA. 5040\t\tB. 720\nC. 120\t\tD. 5050\n\n";
                if(getch()=='A')
                {
                    cout<<"Corrent!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is A";
                    getch();
                }
                break;
            case 10:
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\nQ10.Samsung is of Which country? ";
                cout<<"\n\nA. India\t\tB. China\nC. South Korea\t\tD. Japan\n\n";
                if(getch()=='C')
                {
                    cout<<"Correct!!!";
                    count++;
                }
                else
                {
                    cout<<"Incorrect!!! Correct Answer is C";
                    getch();
                }
                break;

            }

        }   //end of for loop of Play game
        fstream score;
        score.open("score.txt",ios::app);
        if(!score){
            cout<<"File is not Created";
        }
        else{
            score<<endl<<playerName<<" "<<count;
            //system("cls");

        }
        score.close();
    }       //end of Play game
    else if(choice==2)
    {
        fstream newfile;
         newfile.open("score.txt",ios::in); //open a file to perform read operation using file object
        if (newfile.is_open()){   //checking whether the file is open
        string tp;
        while(getline(newfiletp)){ //read data from file object and put it into string.
            cout << tp << "\n"; //print the data of the string
      }
      newfile.close(); //close the file object.
        }
    }
    goto score;
        score:
            system("cls");
            cout<<"Your Total Points is: "<<count<<endl;
            if(count>=5)
            {
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t****CONGRATULATION You Won This Game******";
                goto  mainScreen;
            }
            else{
                system("cls");
                cout<<"Your Total Points is: "<<count<<endl;
                cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\tBetter Luck!! Next Time";
                goto mainScreen;
            }
}

OUTPUT:





YouTube Video Link:


1 comment:

Full Specification of Redmi Note 10, Note 10 Pro and Note 10 Pro Max

  Redmi Note 10 Pro Max General Brand Xiaomi Model Redmi Note 10 Pro Max Price in India ₹18,999 Release date 4th March 2021 Launched in Indi...