I am almost done with my second program ever created in C and I need some help to make it run again after it gives me the answer! What it does, it quits and I have to run it again and again! I just want it to bring me back to selection of choice menu when it is done!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main( )
{
int x;
int y;
int choice;
printf ( "Hello! This is the second version of my calculator\n" );
printf ( "Select addition or subtraction\n" );
printf ( "1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n");
scanf ("%d", &choice);
if ( choice == 1 )
{
printf ( "You chose addition!\n\n" );
printf ( "Input the first integer,x:\n" );
scanf ("%d", &x);
printf ( "Input the second integer,y:\n" );
scanf ("%d", &y);
printf ("The sum is: %d\n", x + y );
}
else if ( choice == 2 )
{
printf ( "You chose subtraction ( Note that this calculator will subtract the second term (y) from the first term (x)\n\n" );
printf ( "Input the first integer,x:\n" );
scanf ( "%d", &x );
printf ( "Input the second integer,y:\n" );
scanf ( "%d", &y );
printf ( "The difference is: %d\n", x - y );
}
else if (choice == 3)
{
printf ("You chose Multiplication!\n\n");
printf ("Input the first integer,x:\n");
scanf ("%d", &x);
printf ("Input the second integer,y:\n");
scanf ("%d", &y);
printf ("The product is:%d\n", x * y);
}
else if (choice == 4)
{
printf ("You chose division!\n\n");
printf ("Input the first integer,x:\n");
scanf ("%d", &x);
printf ("Input the second integer, y:\n");
scanf ("%d", &y);
printf ("The result is:%d\n", x / y);
}
else
{
printf ("INVALID CHOICE! EXITTING!\n");
}
}
I know I should have used switch statement, I will probably rewrite since that is also a good practice