about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

Calculator, Essay, Game Program in C++

 

 

 

 

 

Calculator, Essay writing and Game all three features in a single C++ program. Yes we are doing now some fun with the C++ language. We will develop a C++ program which will ask the user to either perform calculation, Write Essay or play a game.


So just execute and understand this code and see what happens. One thing just keep in mind this program will run on Dev C++ IDE. If you are using some other compiler you have to modify the code for execution. So let’s go.


Code


//date 3 february 2019

//program using switch and function

#include<iostream>

#include<string.h>

#include<conio.h>

using namespace std;

void calculator();

void essay();

void game();

int main()

{

            char choice;

            cout<<"\n\t\tPress C to open Calculator\n\t\tPress E to Write an Essay\n\t\tPress G to play a Game\n";

            cin>>choice;

            switch(choice)

            {

                        case 'C':

                        case 'c':

                                    calculator();

                                    break;

                        case 'E':

                        case 'e':

                                    essay();

                                    break;

                        case 'G':

                        case 'g':

                                    game();

                                    break;

                        default:

                                    cout<<"You Press Invalid Key\n";

            }

            return 0;

}

void calculator()

{

            int num1,num2,result;

            char option;

            cout<<"\t\t\tCasio Calculator\n";

            cout<<"\nPerform any Arthimatic Operation in the Following Format\n";

            cout<<"value1 operation value2 =Answer\n";

            cin>>num1>>option>>num2;

            switch(option)

            {

                        case '+':

                                    result=num1+num2;

                                    cout<<num1<<" + "<<num2<<" = "<<result<<endl;

                                    break;

                        case '-':

                                    result=num1-num2;

                                    cout<<num1<<" - "<<num2<<" = "<<result<<endl;

                                    break;

                        case '*':

                                    result=num1*num2;

                                    cout<<num1<<" * "<<num2<<" = "<<result<<endl;

                                    break;

                        case '/':

                                    result=num1/num2;

                                    cout<<num1<<" / "<<num2<<" = "<<result<<endl;

                                    break;

                        case '%':

                                    result=num1%num2;

                                    cout<<num1<<" % "<<num2<<" = "<<result<<endl;

                                    break;

                        default:

                                    cout<<"\nInvalid operator is Used\n";

            }

           

}

void essay()

{

    int len=5000;

    char str[len];

            cout<<"Welcome To the Ms Word press $ to end\n";

    cin.get(str,len,'$');

    cout<<"\n\tYour Essay :\n\n\t\t\t"<<str;

           

}

void game()

{

            char count;

            cout<<"\n\tWelcome To the Helicopter / Tank Game\n";

            cout<<"\nA Terrorist Gang Have Now just Cross the Divender Line.\n\n";

            cout<<"\nYou are on the Pakistani Al-Khalid Tank. Shot the Terrorists \n\n";

            cout<<"\nBy just Adjusting Your Tank's Missile Range and Height.\n";

            do{

           

                        int height;

                        int range;

                        cout<<"\nEnter the Range and Height To Shot \n";

                        cin>>range>>height;

                        if(range==1000&&height==1000)

                        {

                       

                        cout<<"\n\tCongratulations! Succesfully Shot the Terrorists Gang\n";

               }

            else{

                        cout<<"\n\t\t\tMissile Passes away Missing its Target \n";

            }

             cout<<"Want to Shot again y/n\n";

            cin>>count;

            }

           

while(count!='n');

}


/* End of the Program*/




 

Output


Below are some sample outputs for the above code.

 

Output for the scenario of Calculator


 

 

 

Output in case of Essay Writing

 

 


 

 

Output for Playing game

 

 

 


Thank you for understanding this article if any trouble please comment us. Our rapid response system will take a rapid action.


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents