Calculator

Sample Output:


Source code:

#include
#include
#include


void add(int x, int y, int z);
void sub(int x, int y, int z);
void pro(int x, int y, int z);
void div(float x, float y, float z);


main()
{

system ("cls");



int a, b, c;

char choice;

printf("Menu:\n");
printf("[+]Add\n");
printf("[-]Subtract\n");
printf("[*]Multiply\n");
printf("[/]Divide\n");
printf("[e]Exit\n");
printf("Choice:");
scanf("%s",&choice);


if(choice=='e')
{
return 0;

}



if(choice=='+')
{

printf("\n\nEnter Num1:");
scanf("%d",&a);
printf("Enter Num2:");
scanf("%d",&b);
printf("Enter Num3:");
scanf("%d",&c);

add(a, b, c);

char doll;
printf("\n\nReturn to Menu? Y or y for yes, N or n to exit prog
ram: ");
scanf("%s",&doll);



if((doll=='Y')||(doll=='y'))
{
return main();
}

else return 0;
}


if(choice=='-')
{

printf("\n\nEnter Num1:");
scanf("%d",&a);
printf("Enter Num2:");
scanf("%d",&b);
printf("Enter Num3:");
scanf("%d",&c);
sub(a, b, c);

char doll;
printf("\n\nReturn to Menu? Y or y for yes, N or n to exit program: ");
scanf("%s",&doll);


if((doll=='Y')||(doll=='y'))
{
return main();

}

else return 0;

}
if(choice=='*')
{
printf("\n\nEnter Num1:");
scanf("%d",&a);
printf("Enter Num2:");
scanf("%d",&b);
printf("Enter Num3:");

scanf("%d",&c);
pro(a, b, c);


char doll;
printf("\n\nReturn to Menu? Y or y for yes, N or n to exit program: ");
scanf("%s",&doll);


if((doll=='Y')||(doll=='y'))
{

return main();
}


else return 0;
}

if(choice=='/')
{
printf("\n\nEnter Num1:");

scanf("%d",&a);
printf("Enter Num2:");
scanf("%d",&b);
printf("Enter Num3:");

scanf("%d",&c);
div(a, b, c);

char doll;
printf("\n\nReturn to Menu? Y or y for yes, N or n to exit program: ");
scanf("%s",&doll);


if((doll=='Y')||(doll=='y'))
{

return main();
}

else return 0;
}

else
return 0;




getch();
}


void add(int x, int y, int z)
{
int sum=0;
sum=x+y+z;
printf("\n%d+%d+%d is equal to %d",x, y, z, sum);
}

void sub(int x, int y, int z)
{
int sub1=0;
sub1=x-y-z;
printf("\n%d-%d-%d is equal to %d",x, y, z, sub1);
}
void pro(int x, int y, int z)
{

int pro1=1;
pro1=x*y*z;
printf("\n%d*%d*%d is equal to %d",x, y, z, pro1);

}
void div(float x, float y, float z)
{
float div=1, div2=0;
div=x/y;
div2=div/z;
printf("\n%.0f/%.0f/%.0f is equal to %.2f",x, y, z, div2);

}

1 comments:

michel said...

#include iostream
using namespace std

main()
{
int num[5]={0};
int x,search=0,sum=0;
cout<<"Input 5 values: ";
cin>>num[0]>>num[1]>>num[2]>>num[3]>>num[4];
cout<<"Search value: ";
cin>>search;
for(int x=0;x<=4;x++)
if(num[x]==search)
{
cout<<"FOUND"
}
cout<<"NOT FOUND"

Post a Comment