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 Language program. Yes we are going to make 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 whether your output is same or not. One thing to be noted, that this program will run on Dev C++ IDE. If you are using some other Integrated Development Environment then you have to modify the program for execution. So let’s go.



Code


//date 3 february 2019

//program using switch and function

#include<stdio.h>

#include<string.h>

#include<conio.h>

void calculator();

void essay();

void game();

int main()

{

            char choice;

            printf("\n\t\tPress C to open Calculator\n\t\tPress E to Write an Essay\n\t\tPress G to play a Game\n");

            scanf("%c",&choice);

            switch(choice)

            {

                        case 'C':

                        case 'c':

                                    calculator();

                                    break;

                        case 'E':

                        case 'e':

                                    essay();

                                    break;

                        case 'G':

                        case 'g':

                                    game();

                                    break;

                        default:

                                    printf("You Press Invalid Key\n");

            }

            return 0;

}

void calculator()

{

            int num1,num2,result;

            char option;

            printf("\t\t\tCasio Calculator\n");

            printf("\nPerform any Arthimatic Operation in the Following Format\n");

            printf("value1 operation value2 =Answer\n");

            scanf("%d%c%d",&num1,&option,&num2);

            switch(option)

            {

                        case '+':

                                    result=num1+num2;

                                    printf("%d + %d = %d",num1,num2,result);

                                    break;

                        case '-':

                                    result=num1-num2;

                                    printf("%d - %d = %d",num1,num2,result);

                                    break;

                        case '*':

                                    result=num1*num2;

                                                printf("%d * %d = %d",num1,num2,result);

                                    break;

                        case '/':

                                    result=num1/num2;

                                    printf("%d / %d = %d",num1,num2,result);

                                    break;

                        case '%':

                                    result=num1%num2;

                                                printf("%d % %d = %d",num1,num2,result);

                                    break;

                        default:

                                    printf("\nInvalid operator is Used\n");

            }

           

}

void essay()

{

    int len=5000;

    char str[len];

            printf("Welcome To the Ms Word .Press Enter to End the Essay.\n");

            fflush(stdin);

    gets(str);

    printf("\n\tYour Essay :\n\n\t\t\t%s",str);

           

}

void game()

{

            char count;

            printf("\n\tWelcome To the Helicopter / Tank Game\n");

            printf("\nAn Indian Helicopters Have Now just Cross the Line of Control.\n\n");

            printf("\nYou are on the Pakistani Al-Khalid Tank. Shot the Helicopter \n\n");

            printf("\nBy just Adjusting Your Tank's Missile Range and Height.\n");

            do{

           

                        int height;

                        int range;

                        printf("\nEnter the Range and Height To Shot \n");

                        scanf("%d%d",&range,&height);

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

                        {

                       

                        printf("\n\tCongratulations! Succesfully Shot the Indian Helicopter\n");

                        break;

               }

            else{

                        printf("\n\t\t\tMissile Passes away Missing the Helicopter \n");

            }

             printf("Want to Shot again press y else n \n");

            scanf("%c",&count);

            }

           

while(count!='n');

if(count=='n')

printf("\nHelicopter Leave the Pakistani Lands\n");

}



Output

Now these are some sample outputs

 

Output for the scenario of Calculator

 

 

 

Output in case of Essay Writing

 

 



 

 

Output for Playing game

 

 

 

Thanks everyone, We like it, if someone comments or share us.

 


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents