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. -
/*
-
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;
-
-
}
-
-
2 1578
I think one of the standard libraries has this, however (as I'm not really sure which one) it is a reasonably simple method to implement.....
Thsi method will change an upper case to a lower case (since that is what you test for) -
-
char toLower(char myChar)
-
{
-
if((myChar >= 'A') && (myChar <='Z')
-
{
-
return (myChar -('A' - 'a'));
-
}
-
return myChar; //character is already lowercase or not a char that has case
-
}
-
You can either do
teacher = toLower(teacher) when you first read teacher in (probably the better idea), or you can use this at each if (if(toLower(teacher) == 'y')) (not such a good idea, because it means alterring LOTS of code)
Either that, or every time you test for 'y', you test if it equals 'y' OR it equals 'Y'. Same with 'n'.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mohammed Mazid |
last post by:
Can anyone please help me on how to move to the next and previous
question?
Here is a snippet of my code:
Private Sub cmdNext_Click()
End Sub
Private Sub cmdPrevious_Click()
showrecord
|
by: nospam |
last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types,
so, since it seems to me that Partial Types is still in the design or
development stages at Microsoft, I am going to ask...
|
by: Simon Harvey |
last post by:
Hi everyone,
I was wondering if it is possible, to use SQL to return more than one table
at a time into a dataset. I only know the basics of SQL and so I'm not sure
if I'm just asking a stupid...
|
by: lester |
last post by:
a pre-beginner's question:
what is the pros and cons of .net, compared to ++
I am wondering what can I get if I continue to learn C# after I have learned
C --> C++ --> C# ??
I think there...
|
by: sea |
last post by:
I have 2 applications, one a Microsoft Visual Basic application and
the other a Java application both connecting to the same DB2 database.
The database has binary LOB objects. The Visual Basic...
|
by: Mark Yudkin |
last post by:
The documentation is unclear (at least to me) on the permissibility of
accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003,
with separate transactions scope, from separate...
|
by: Ekqvist Marko |
last post by:
Hi,
I have one Access database table including questions and answers. Now
I need to give answer id automatically to questionID column. But I
don't know how it is best (fastest) to do?
table...
|
by: Elaine |
last post by:
This has to do with self-joins and includes a running balance problem.
Is it possible to do this using SQL alone?
Amortization schedule
--------------------------
Givens: beginning balance,...
|
by: jojobar |
last post by:
Hello,
I am trying to use vs.net 2005 to migrate a project originally in vs.net
2003. I started with creation of a "web site", and then created folders for
each component of the site.
I read...
|
by: spibou |
last post by:
In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a * (b+c)" or "a = a * b+c" ?
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |