Here is my problem, my code is working correctly, and the program is functioning as it should, however I want the person using the program to be able to enter 'y', 'Y', 'n', or 'N' for whether or not the buyer is a teacher, currently I have it setup to where the only way it works is with the lowercase 'y' and 'n' .... could someone please check my code below and tell me what I need to add to have this work with the uppercase letters as well. Thanks.
Code:
/*
File: lab3.c
Author: Nick Cantey
Description: This program calculates and prints a receipt for purchases.
Date created: 2/22/2007
*/
#include <stdio.h>
/* Constants for program */
#define TEACHER_DISCOUNT_SMALL 0.1
#define TEACHER_DISCOUNT_BIG 0.12
#define SALES_TAX 0.05
int main ()
{
FILE* out; /* sets out to point to a file */
char teacher; /* sets teacher to be a variable for main */
double salesTax, purchase_amount, discount, discount_total, total; /* variables for main */
/* Prompting for total price of purchase and if buyer is a teacher */
printf("Please enter total purchase amount: ");
scanf("%lf", &purchase_amount);
fflush(stdin);
printf("Is customer a music teacher (y/n)?: ");
scanf("%c", &teacher);
/* Opens receipt file */
out = fopen("receipt.txt", "w");
/* Determines price for teacher with a 12% discount */
if (teacher == 'y' && purchase_amount >=100)
{
discount = purchase_amount*TEACHER_DISCOUNT_BIG;
discount_total = purchase_amount-discount;
salesTax = discount_total*SALES_TAX;
total = discount_total+salesTax;
fprintf(out, "Total Purchase\t\t$%10.2lf\n", purchase_amount);
fprintf(out, "Teacher Discount(12%%)\t$%10.2lf\n", discount);
fprintf(out, "Sales Tax(5%%)\t\t$%10.2lf\n", salesTax);
fprintf(out, "Total\t\t\t$%10.2lf\n", total);
fclose(out);
}
/* Determines price for teacher with a 10% discount */
else if ( teacher == 'y' && purchase_amount <100)
{
discount = purchase_amount*TEACHER_DISCOUNT_SMALL;
discount_total = purchase_amount-discount;
salesTax = discount_total*SALES_TAX;
total = discount_total+salesTax;
fprintf(out, "Total Purchase\t\t$%10.2lf\n", purchase_amount);
fprintf(out, "Teacher Discount(10%%)\t$%10.2lf\n", discount);
fprintf(out, "Sales Tax(5%%)\t\t$%10.2lf\n", salesTax);
fprintf(out, "Total \t\t\t$%10.2lf\n", total);
fclose(out);
}
/* Determines price for a regular customer */
else if ( teacher == 'n' && purchase_amount >0 )
{
salesTax = purchase_amount*SALES_TAX;
total = purchase_amount+salesTax;
fprintf(out, "Total Purchase\t\t$%10.2lf\n", purchase_amount);
fprintf(out, "Sales Tax(5%%)\t\t$%10.2lf\n", salesTax);
fprintf(out, "Total\t\t\t$%10.2lf\n", total);
fclose(out);
}
return;
}
Comment