#include #include //This program should // 1) ask the user first for the number of orders: numorders (between 1-3) // 2) check that numorders is within the desired range // 3) prompt the user for the cost of each order and output the total at the end int main() { int numorders; float cost1=0, cost2=0, cost3=0; float total; printf("Enter the number of orders:"); scanf("%d", &numorders); //check for an incorrect number of orders if(numorders < 0 || numorders > 3) { printf("Invalid number of orders!\n"); } else { //correct number of orders, get the cost of each order //note the hierarchical if statements if(numorders > 0) { //this is executed when numorders is 1, 2, or 3 printf("Enter the cost of the 1st order: "); scanf("%f", &cost1); if(numorders > 1) { //this is executed when numorders is 2, or 3 printf("Enter the cost of the 2nd order: "); scanf("%f", &cost2); if(numorders > 2) { //this is executed when numorders is 3 printf("Enter the cost of the 3rd order: "); scanf("%f", &cost3); } } } //sum the costs total = cost1+cost2+cost3; printf("The total for the order is: %.2f\n", total); } system("pause"); }