what i write the programming is input (product number)<space>(quantity) then it will print the (price according the product number * quantity) .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(); }
but what i want the program is it can total up all the different product price once i type -1.
This is the output what i need.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
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.



LinkBack URL
About LinkBacks


