About mathematical programming problem...

This is a discussion on About mathematical programming problem... within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h>int num1; void a() { printf( "%f\n",3.40*num1 ); } void b() { printf( "%f\n",11.30*num1 ); } void c() ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    14

    About mathematical programming problem...

    Code:
    #include <stdio.h>int num1;
    void a()
    {
        printf( "%f\n",3.40*num1 );
    }
    void b()
    {
        printf( "%f\n",11.30*num1 );
    }
    void c()
    {
        printf( "%f\n",4.78*num1 );
    }
    
    
    int main()
    {
        while (1)
        {
    
    
        int input;
    
    
    printf ("Enter pairs of item numbers and quantities.\n");
    printf ("Enter -1 for the item number to end input.\n");
    
    
        scanf ("%d %d", &input ,&num1);
        switch ( input ) {
            case 1:            /* Note the colon, not a semicolon */
                a();
                break;
            case 2:
                b();
                break;
            case 3:
                c();
                break;
            case -1:
                printf( "The total retail value was USD:\n");
                break;
            default:
                printf( "Invalid product code:  %d,input\n" );
                break;
    
    
        }}
        getchar();
    
    
    }
    what i write the programming is input (product number)<space>(quantity) then it will print the (price according the product number * quantity) .
    but what i want the program is it can total up all the different product price once i type -1.

    Code:
    Enter pairs of item numbers and quantities.
    Enter -1 for the item number to end input.
    1 1
    2 1
    3 1
    4 1
    Invalid product code:  4
    1 1
    -1
    The total retail value was: USD22.88
    This is the output what i need.
    how to write the program that once i input "1 1" then it still can input continuously until i input -1 it will show up sum of the price?
    Please correct my program, thanks.
    Last edited by yeohwl91; 09-27-2011 at 09:17 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Well you need to store
    printf( "%f\n",3.40*num1 );
    somewhere, not just print it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with C programming Mathematical Calculations
    By StangFan in forum C Programming
    Replies: 7
    Last Post: 01-15-2010, 05:09 PM
  2. help with mathematical problem in C
    By feelseez in forum C Programming
    Replies: 3
    Last Post: 09-10-2006, 12:44 PM
  3. Mathematical, nautical steering problem
    By Warlax in forum Game Programming
    Replies: 6
    Last Post: 06-16-2006, 07:01 PM
  4. Mathematical problem
    By Warlax in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2006, 03:38 AM
  5. Problem with a mathematical formula
    By BianConiglio in forum C Programming
    Replies: 13
    Last Post: 04-30-2005, 12:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21