Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h> /*for toupper*/
#include <string.h> /*needed for strcpy()*/
#define MAX_NAME 30
#define TITLE "Mabuhay Video Store"
#define MAX_VIDEO 10
void getcustomer(char Fullname[],char Address[],char City[],
char CouponApplied[]);
void getVideos(char Fullname[],char CouponApplied[],char VideoTitle[][MAX_NAME + 1],
char Category[], int DaysRented[]);
void computecharges(float price[], int DaysRented[], char Category[]);
void displayreceipt(char Fullname[],char Address[],char City[],
char VideoTitle[][MAX_NAME + 1],char Category[],
int DaysRented[],char CouponApplied[],
char Late[][5],float price[]);
void initialise(char VideoTitle[][MAX_NAME + 1],char Category[],char Late[][5],
float price[],int DaysRented[]);
float Tax, Charge;
char Y;
int main(void)
{
int choice;
int DaysRented[MAX_VIDEO];
float Tax, Charge;
float price[MAX_VIDEO];
char No ='N'; /*you don't use this in your prog*/
char Fullname[MAX_NAME + 1];
char Address[MAX_NAME + 1];
char City[MAX_NAME + 1];
char VideoTitle[MAX_VIDEO][MAX_NAME + 1]; /*allow ten titles*/
char Category[MAX_VIDEO + 1]; /*allow ten categories*/
char CouponApplied[4]; /*YES or NO 3 + null*/
char Late[MAX_VIDEO][5]; /*does this string hold either late or lost, if
so then 4 + null is all you need
You don't seem to allow the user to input a value
for this but you use it in displayreceipt()*/
do
{
system ("cls");
printf("=============================\n");
printf(" %s\n", TITLE);
printf("=============================\n\n");
printf("1 Enter Customer Information\n");
printf("2 Enter Rental Information\n");
printf("3 Compute Charges\n");
printf("4 Display Receipt\n");
printf("5 Exit Program\n\n");
printf(" Selection: ");
scanf("%d",&choice);
getchar();
if(choice==1)
{
/*intialise next customer*/
initialise(VideoTitle,Category,Late,price,DaysRented);
getcustomer(Fullname,Address,City,CouponApplied);
}
else if(choice==2)
{
getVideos(Fullname,CouponApplied, VideoTitle,Category, DaysRented);
}
else if(choice==3)
{
computecharges(price, DaysRented, Category);
}
else if(choice==4)
{
displayreceipt(Fullname, Address, City,VideoTitle, Category,
DaysRented, CouponApplied, Late,price);
}
else
{
break;
}
}
while(choice!=5);
return EXIT_SUCCESS;
}
//header
void getcustomer(char Fullname[], char Address[], char City[],
char CouponApplied[])
{
system("cls");
printf("Store Name: %s\n\n", TITLE);
printf("Customer Name: ");
gets(Fullname);
printf("Address: ");
gets(Address);
printf("City/State/Zip: ");
gets(City);
printf("Coupon (Y/N): ");
/*this may be better it's up to you or anyone else who
knows better*/
/*scanf("%c", &Y);*/
Y = toupper(getchar());
/*guessing this is what you want*/
if(Y == 'Y')
strcpy(CouponApplied, "YES");
else
strcpy(CouponApplied, "NO");
}
//header
void getVideos(char Fullname[],char CouponApplied[],char VideoTitle[][MAX_NAME + 1],
char Category[], int DaysRented[])
{
int i, count;
char user_resp; /*users response*/
system("cls");
printf("Store Name: %s\n\n", TITLE);
printf("Customer Name: %s\n", Fullname);
printf("Coupon Presented: %s\n\n", CouponApplied);
/*user has to rent 10 videos using for loop
surely you have to allow for any number of
videos between 1 and 10 inclusive*/
printf("How many videos > ");
scanf("%d",&count);
getchar();
for (i = 0; i < count; i++)
{
printf("%i. VideoTitle: ", i+1);
gets(VideoTitle[i]);
printf("Category(N,R,C,B): ");
scanf("%c",&Category[i]);
printf("DaysRented: ");
scanf("%d", &DaysRented[i]);
getchar();
}
}
//header
void computecharges(float price[], int DaysRented[], char Category[])
{
int i;
i = 0;
Tax = Charge = 0.0;
while((Category[i] != ' ') && (Category[i] != '\0'))
{
if (Category[i] == 'N')
price[i] = DaysRented[i] * 2.99;
else if (Category[i] =='R')
{
price[i] = DaysRented[i] * 3.99;
if (Y == 'Y')
price[i] = price[i] - 1.0;
}
else if (Category[i] == 'C')
{
price[i] = DaysRented[i] * 2.99;
if (Y == 'Y')
price[i] = price[i] - 1.0;
}
else if (Category[i] == 'B')
price[i] = DaysRented[i] * 1.0;
else if (DaysRented[i] == 0) /*Don't know*/
price[i] = 75.0; /*why price*/
/*should equal*/
else if (DaysRented[i] == 90) /*75. Dollars I assume?*/
price[i] = 75.0;
Charge += price[i];
i++;
}
Tax = 0.086 * Charge;
/* price = price + price * 0.086; price + price * 86????*/
}
//header
void displayreceipt(char Fullname[],char Address[],char City[],
char VideoTitle[][MAX_NAME + 1],char Category[],int DaysRented[],
char CouponApplied[], char Late[][5], float price[])
{
int i = 0;
system("cls");
printf("Store Name : %s\n\n", TITLE);
printf("Customer Name : %s\n", Fullname);
printf("Address : %s\n", Address);
printf("City/State/Zip : %s\n", City);
printf("Coupon (Y/N) : %c", Y);
printf("Days Coupon\n");
printf("No. Video Title Cat Rent Late/Lost Price\n");
printf("=== =========== === ==== ========= =====\n");
while((Category[i] != ' ') && (Category[i] != '\0'))
{
printf("%-4i%-31s%-5c%-4d%-10s%.2f\n", i + 1, VideoTitle[i], Category[i], DaysRented[i],
Late[i], price[i]);
i++;
}
printf("\n\nSubtotal : %5.2f"
"\nTax (8.6%%) : %5.2f"
"\nTotal Due : %5.2f", Charge,Tax,Tax+Charge);
printf("\n\nHit any key to continue");
rewind(stdin);
getch();
}
void initialise(char VideoTitle[][MAX_NAME + 1],char Category[],char Late[][5],
float price[],int DaysRented[])
{
/*you might want to add or remove items to be initialised, just did this to
avoid random results when accessing values*/
int i;
for(i = 0; i < MAX_VIDEO; i++)
{
strcpy(VideoTitle[i], "\0");
strcpy(Late[i], " ");
Category[i] = ' ';
price[i] = 0.0;
DaysRented[i] = 0;
}
Category[i] = '\0';
}
There are better ways to do this but I'm sure you haven't got that far in your studies yet.