u have done this program in cpp and saved it with extension ".c" . Two solutions exist:
1).save the program as pgname.cpp
2).
(i)use header file #include<stdio.h>
(ii)use printf() in place of cout
(iii)use scanf() in place of cin
the resultant code is as follows:
Code:
#include <stdio>
using namespace std; //Added
//
#include <iomanip>
int main()
{
int product, quantity;
double total = 0.0;
// display headers
printf("Enter pairs of item numbers and quantities.\n Enter -1 for the item number to end input.\n");
scanf("%d",&product);
while ( product != -1 )
{
scanf("%d",&quantity);
switch ( product ) // switch statment nested in while
{
case 1:
total += quantity * 2.98;
break; // necessary to exit switch
case 2:
total += quantity * 4.50;
break; //exit switch
case 3:
total += quantity * 9.98;
break; // exit switch
case 4:
total += quantity * 4.49;
break; // exit switch
case 5:
total += quantity * 6.87;
break; // exit switch
default: // catch all other characters
printf("Invalid product code: %d \n Quantity: %d",product,quantity);
break;// optional; will exit switch anyway
} // end switch
cout << "Enter pairs of item numbers and quantities.\n"//change these places also
<< "Enter -1 for the item number to end input: ";
cin >> product;
} // end while
cout << setiosflags( ios::fixed | ios::showpoint )
<< "The total retail value was: " << setprecision( 2 )
<< total << endl;
return 0; // indicate successful termination
} // end function