/*Program 6 Validation, For and Switch Oh My!*/ /*Eric Moffett: dblefault@yahoo.com*/ /*3/01/01*/ #include int main() { int customer; /*number of customers*/ int gastype; /*type of gas*/ int counter; int regCustomers=0; /*used for the number of regular customers*/ int plusCustomers=0; /*used for the number of plus customers*/ int supCustomers=0; /*used for the number of super customers*/ double regGallons=0; /*used for the number of regular gallons*/ double plusGallons=0; /*used for the number of plus gallons*/ double supGallons=0; /*used for the number of super gallons*/ double regRevenues=0; /*used for the number of regular revenues*/ double plusRevenues=0; /*used for the number of plus revenues*/ double supRevenues=0; /*used for the number of super revenues*/ double gallons; /*gallons purchased by customer*/ double total; /*cost for each individual customer*/ double regular=1.399; /*cost of regular gas*/ double plus= 1.499; /*cost of plus gas*/ double super= 1.599; /*cost of super gas*/ double revenues=0; /*toytal revenues of all gas*/ /*Enter number of customers*/ printf("Welcome to the GasCo Calculator Program\n"); printf("How many customers to process right now?\n"); scanf("%d", &customer); /*loop used to prevent negative inputs*/ while (customer<0) { printf("Welcome to the GasCo Calculator Program\n"); printf("How many customers to process right now?\n"); scanf("%d", &customer); } /*loop used to run through all customers*/ for (counter=1; counter<=customer; counter++) { printf("Please enter gas type (1 - regular; 2 - plus; 3 - super):"); scanf("%d", &gastype); /*customer enters gastype to purchase*/ /*loop used to prevent invalid input by user*/ while (gastype!=1 && gastype!=2 && gastype!=3) { printf("Please enter gas type (1 - regular; 2 - plus; 3 - super):"); scanf("%d", &gastype); } printf("\n"); /*switch used to handle the three types of gas*/ switch ( gastype ) { case 1: /*regular gas*/ printf("Please enter the number of gallons purchased (between 1/2 and 30): "); scanf("%lf", &gallons); printf("\n"); /*loop used to prevent invalid input*/ while (gallons< 0.5 || gallons>30.0) { printf("Please enter the number of gallons purchased (between 1/2 and 30): "); scanf("%lf", &gallons); printf("\n"); } total= gallons * regular; /*calulates cost for customer*/ regCustomers++; /*keeps total of regular customers*/ regGallons= regGallons + gallons; /*keeps total of regular gallons*/ regRevenues= regRevenues + total; /*keeps total of regular revenues*/ revenues= revenues + total; /*keeps total of all revenues*/ /*displays info to user*/ printf("customer: %d price: %6.3f gallons: %6.1f total: %6.2f \n", counter, regular, gallons, total); printf("\n"); break; case 2: /*plus gas*/ printf("Please enter the number of gallons purchased (between 1/2 and 30): "); scanf("%lf", &gallons); printf("\n"); /*loop used to prevent invalid input*/ while (gallons< 0.5 || gallons>30.0) { printf("Please enter the number of gallons purchased (between 1/2 and 30): "); scanf("%lf", &gallons); printf("\n"); } total= gallons * plus; /*calulates cost for customer*/ plusCustomers++; /*keeps total of plus customers*/ plusGallons= plusGallons + gallons; /*keeps total of plus gallons*/ plusRevenues= plusRevenues + total; /*keeps total of plus revenues*/ revenues= revenues + total; /*keeps total of all revenues*/ /*displays info to user*/ printf("customer: %d price: %6.3f gallons: %6.1f total: %6.2f \n", counter, plus, gallons, total); printf("\n"); break; case 3: printf("Please enter the number of gallons purchased (between 1/2 and 30): "); scanf("%lf", &gallons); printf("\n"); /*loop used to prevent invalid input*/ while (gallons< 0.5 || gallons>30.0) { printf("Please enter the number of gallons purchased (between 1/2 and 30) "); scanf("%lf", &gallons); printf("\n"); } total= gallons * super; /*calulates cost for customer*/ supCustomers++; /*keeps total of super customers*/ supGallons= supGallons + gallons; /*keeps total of super gallons*/ supRevenues= supRevenues + total; /*keeps total of super revenues*/ revenues= revenues + total; /*keeps total of all revenues*/ /*displays info to user*/ printf("customer: %d price: %6.3f gallons: %6.1f total: %6.2f \n", counter, super, gallons, total); printf("\n"); break; } } /*displays end results to user with formatting*/ printf("====================================================================\n"); printf("\n"); printf("Totals:\n"); printf("\t Type of Gas\t #Customers\t Num Gallons\t Revenues\n"); printf("\t ===========\t ==========\t ===========\t ========\n"); printf("\t Regular \t %d \t %6.1f \t %6.2f\n", regCustomers, regGallons, regRevenues); printf("\t Plus \t %d \t %6.1f \t %6.2f\n", plusCustomers, plusGallons, plusRevenues); printf("\t Super \t %d \t %6.1f \t %6.2f\n", supCustomers, supGallons, supRevenues); printf("\t \t \t \t ========\n"); printf("\t \t \t \t %6.2f\n", revenues); return 0; }