#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> void PrintAStarLine(void); void GetInput(void); void GetTicket(void); void HowManyChildren(void); void HowManyAdults(void); void HowManySeniors(void); void ChildrenCalculations(void); float DailyChild; float YearlyChild; float DailyAdult; float YearlyAdult; float DailySenior; float YearlySenior; char customerName[30]; char tickettype[8]; int childrenNum; int adultNum; int seniorNum; main() { { PrintAStarLine(); printf(" Home Aquarium Data Entry \n"); printf("\n\n"); PrintAStarLine(); GetInput(); } GetTicket(); return 0; } void PrintAStarLine(void) { printf("**************************************************************************** \n"); printf("\n\n"); return; } void GetInput(void) { printf("Customer Name (First Middle Last): "); scanf(" %s %s %s", &customerName); printf("\n\n\n"); return; } void GetTicket(void) { printf("Type of ticket (Daily(D) or Yearly(Y)): "); scanf(" %s", &tickettype); if (strcmp (tickettype,"D") == 0) { HowManyChildren(); HowManyAdults(); HowManySeniors(); printf("Children total cost: %10.2f\n", DailyChild); printf("Adult total cost: %10.2f\n", DailyAdult); printf("Senior total cost: %10.2f\n", DailySenior); } else if (strcmp (tickettype,"d") == 0) { HowManyChildren(); HowManyAdults(); HowManySeniors(); printf("Children total cost: %10.2f\n", DailyChild); printf("Adult total cost: %10.2f\n", DailyAdult); printf("Senior total cost: %10.2f\n", DailySenior); } else if (strcmp (tickettype,"Daily") == 0) { HowManyChildren(); HowManyAdults(); HowManySeniors(); printf("Children total cost: %10.2f\n", DailyChild); printf("Adult total cost: %10.2f\n", DailyAdult); printf("Senior total cost: %10.2f\n", DailySenior); } else if (strcmp (tickettype,"daily") == 0) { HowManyChildren(); HowManyAdults(); HowManySeniors(); printf("Children total cost: %10.2f\n", DailyChild); printf("Adult total cost: %10.2f\n", DailyAdult); printf("Senior total cost: %10.2f\n", DailySenior); } else if (strcmp (tickettype,"Y") == 0) { HowManyChildren(); HowManyAdults(); HowManySeniors(); printf("Children total cost: %10.2f\n", YearlyChild); printf("Adult total cost: %10.2f\n", YearlyAdult); printf("Senior total cost: %10.2f\n", YearlySenior); } else if (strcmp (tickettype, "y") == 0) { HowManyChildren(); HowManyAdults(); HowManySeniors(); printf("Children total cost: %10.2f\n", YearlyChild); printf("Adult total cost: %10.2f\n", YearlyAdult); printf("Senior total cost: %10.2f\n", YearlySenior); } else if (strcmp (tickettype,"Yearly") == 0) { HowManyChildren(); HowManyAdults(); HowManySeniors(); printf("Children total cost: %10.2f\n", YearlyChild); printf("Adult total cost: %10.2f\n", YearlyAdult); printf("Senior total cost: %10.2f\n", YearlySenior); } else if (strcmp (tickettype,"yearly") == 0) { HowManyChildren(); HowManyAdults(); HowManySeniors(); printf("Children total cost: %10.2f\n", YearlyChild); printf("Adult total cost: %10.2f\n", YearlyAdult); printf("Senior total cost: %10.2f\n", YearlySenior); } else { printf("\nIncorrect Input, please try again.\n"); printf("\n\n\n"); GetTicket(); } printf("\n\n"); return; } void HowManyChildren(void) { DailyChild=1.50; YearlyChild = 5.50; printf("\n"); printf("#of Children: "); scanf(" %d", &childrenNum); printf("\n"); if (childrenNum <= 999) { } else { printf("Invalid Number Entered, please try again."); printf("\n\n\n"); HowManyChildren(); } return; } void HowManyAdults(void) { DailyAdult = 2.00; YearlyAdult = 6.50; printf("\n"); printf("#of Adults: "); scanf(" %d", &adultNum); printf("\n"); if (adultNum <= 999) { } else { printf("Invalid Number Entered, please try again."); printf("\n\n\n"); HowManyAdults(); } return; } void HowManySeniors(void) { DailySenior = 1.25; YearlySenior= 3.75; printf("\n"); printf("#of Seniors: "); scanf(" %d", &seniorNum); printf("\n"); if (seniorNum <= 999) { } else { printf("Invalid Number Entered, please try again."); printf("\n\n\n"); system("pause"); HowManySeniors(); } return ; } void ChildrenCalculations(void) { return; }
int main(void)
void HowManyChildren(void)
{
DailyChild=1.50;
YearlyChild = 5.50;
printf("\n");
printf("#of Children: ");
scanf(" %d", &childrenNum);
printf("\n");
if (childrenNum <= 999)
{
}
else
{
printf("Invalid Number Entered, please try again.");
printf("\n\n\n");
HowManyChildren();
}
return;
}I'm still trying to figure out how to get the calculations to work in my program. If someone can shed some light on that area for me, it would be greatly appreciated. Thanks again.
void HowManySeniors(void) { DailySenior = 1.25; YearlySenior= 3.75; printf("\n"); printf("#of Seniors: "); scanf(" %d", &seniorNum); printf("\n"); if (seniorNum <= 999) { } else { printf("Invalid Number Entered, please try again."); printf("\n\n\n"); system("pause"); HowManySeniors(); } return ; }
if (seniorNum <= 999) /* if Seniors are less or iquals to 999 */ { ; /* do nothing */ }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> void PrintAStarLine(void); void GetInput(void); void GetTicket(void); void HowManyChildren(void); void HowManyAdults(void); void HowManySeniors(void); void TotalCost(void); float DailyChild; float YearlyChild; float DailyAdult; float YearlyAdult; float DailySenior; float YearlySenior; char customerName[30]; char tickettype[8]; int main(void) { { PrintAStarLine(); printf(" Home Aquarium Data Entry \n"); printf("\n\n"); PrintAStarLine(); GetInput(); } GetTicket(); HowManyChildren(); HowManyAdults(); HowManySeniors(); TotalCost(); return 0; } void PrintAStarLine(void) { printf("**************************************************************************** \n"); printf("\n\n"); return; } void GetInput(void) { printf("Customer Name (First Middle Last): "); scanf(" %s %s %s", &customerName); printf("\n\n\n"); return; } void GetTicket(void) { printf("Type of ticket (Daily(D) or Yearly(Y)): "); scanf(" %s", &tickettype); if (strcmp (tickettype,"D") == 0) { } else if (strcmp (tickettype,"d") == 0) { } else if (strcmp (tickettype,"Daily") == 0) { } else if (strcmp (tickettype,"daily") == 0) { } else if (strcmp (tickettype,"Y") == 0) { } else if (strcmp (tickettype, "y") == 0) { } else if (strcmp (tickettype,"Yearly") == 0) { } else if (strcmp (tickettype,"yearly") == 0) { } else { printf("\nIncorrect Input, please try again.\n"); printf("\n\n"); GetTicket(); } printf("\n\n"); return; } void HowManyChildren(void) { DailyChild = 1.50; YearlyChild = 5.50; printf("\n"); printf("#of Children: "); scanf(" %f", &DailyChild); printf("\n"); if (DailyChild <= 999) { ; } else { printf("Invalid Number Entered, please try again."); printf("\n\n\n"); printf("\n"); printf("#of Children: "); scanf(" %f", &YearlyChild); printf("\n"); HowManyChildren(); } if (YearlyChild <= 999) { ; } else { printf("Invalid Number Entered, please try again."); printf("\n\n\n"); HowManyChildren(); } return; } void HowManyAdults(void) { DailyAdult = 2.00; YearlyAdult = 6.50; printf("\n"); printf("#of Adults: "); scanf(" %f", &DailyAdult); printf("\n"); if (DailyAdult <= 999) { ; } else { printf("Invalid Number Entered, please try again."); printf("\n\n\n"); HowManyAdults(); } return; } void HowManySeniors(void) { DailySenior = 1.25; YearlySenior= 3.75; printf("\n"); printf("#of Seniors: "); scanf(" %f", &DailySenior); printf("\n"); if (DailySenior <= 999) { ; } else { printf("Invalid Number Entered, please try again."); printf("\n\n\n"); system("PAUSE"); HowManySeniors(); } return ; } void TotalCost(void) { printf("Children total cost: %10.2f\n", DailyChild); printf("Adult total cost: %10.2f\n", DailyAdult); printf("Senior total cost: %10.2f\n", DailySenior); return ; }
void GetInput(void) { printf("Customer Name (First Middle Last): "); scanf(" %s %s %s", &customerName); printf("\n\n\n"); return; }
/* * HomeDepot.c * Shows how to match item with price. */ #include <stdio.h> float price( const float item ) { int piece = 0; char newline; scanf( "%d%c", &piece, &newline ); /* amount of items */ return item * piece; } int main( void ) { const float screw = .50; /* this never should change */ const float nail = .25; /* this never should change */ float price_screws = 0.00; /* final total price items */ float price_nails = 0.00; /* final total price items */ /* ask for nails */ printf( " Enter amount of nails: " ); fflush( stdout ); /* refresh the screen */ /* get & compute the total price of nails */ price_nails = price( nail ); /* ask for screws */ printf( "Enter amount of screws: " ); fflush( stdout ); /* refresh the screen */ /* get & compute the total price of screws */ price_screws = price( screw ); /* final display */ puts( "\n\tYour total order" ); puts( "\t================\n"); printf( " Price for nails: %6.2f\n", price_nails ); printf( "Price for screws: %6.2f\n", price_screws ); printf( " Grand total: %6.2f\n", price_nails + price_screws ); getchar(); return 0; } /* my input / output. Enter amount of nails: 34 Enter amount of screws: 23 Your total order ================ Price for nails: $ 8.50 Price for screws: $ 11.50 Grand total: $ 20.00 */
| DaniWeb Message | |
| Cancel Changes | |