Thread: About mathematical programming problem...

  1. #1
    Registered User
    Join Date
    Sep 2011

    About mathematical programming problem...

    #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 */
            case 2:
            case 3:
            case -1:
                printf( "The total retail value was USD:\n");
                printf( "Invalid product code:  %d,input\n" );
    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.

    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
    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 08:17 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

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, 11:44 AM
  3. Mathematical, nautical steering problem
    By Warlax in forum Game Programming
    Replies: 6
    Last Post: 06-16-2006, 06:01 PM
  4. Mathematical problem
    By Warlax in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2006, 02:38 AM
  5. Problem with a mathematical formula
    By BianConiglio in forum C Programming
    Replies: 13
    Last Post: 04-29-2005, 11:26 PM