Thread: Making a calculator run again!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    #C-help
    Join Date
    Jun 2007
    Location
    Las Vegas
    Posts
    53

    Question Making a calculator run again!

    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 ("&#37;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
    Last edited by cookie; 06-09-2007 at 01:31 AM. Reason: adding something

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  3. Making control...
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2004, 01:42 PM
  4. Replies: 2
    Last Post: 01-13-2003, 01:28 PM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM