The local flying-disc shop sells premium disc-golf and ultimate (Frisbee) discs.
ID: 3666042 • Letter: T
Question
The local flying-disc shop sells premium disc-golf and ultimate (Frisbee) discs. The disc-golf discs retail for $12.99 and the ultimate discs retail for $18.99 each. Quantity discounts are given as follows:
Write a program that asks the cashier if the customer wishes to purchase disc-golf or ultimate discs. The cashier enters a 'u' or 'U' for ultimate and 'g' or 'G' for disc golf; all other input output an error message exit the program. (Use a switch statement to check the user's input and use return 0; in the switch statement to end the program.). If the input was valid, the program should then prompts the user for the number of discs. If the number is nonnegative, the program displays the disc type, quantity, price per disc, and total price (with exactly 2 decimal places). Otherwise, the program displays the error message, "X is an invalid number of discs" (where X is the number the user inputted).
In your implementation, avoid duplicating your code; arrange the program logic so that no statements are repeated. (Hint: a single string variable is useful to hold either"Ultimate Disc" or "Disc-Golf Disc") Also, define and use constants for the retail prices (e.g., DISC_GOLF_RETAIL, ULTIMATE_RETAIL). You may use additional constants if you choose.
Sample Run (the yellow text is colored is user input):BELOW
Number of Discs Discount 5 – 10 10% 11 – 20 15% 21 – 30 20% 31 or more 25%Explanation / Answer
#include<stdio.h>
#include<conio.h>
float calculateU(int num,int disc)
{
float total,disamt,priceperdisc;
disamt = 18.99*(disc/100);
priceperdisc = 18.99 -(disamt);
total = priceperdisc*num;
printf("Receipt ");
printf("Disc Type: Ultimate Disc Quantity : %d Price per Disc : %f Total : %f ,num,priceperdisc,total");
return 0;
}
float calculateG(int num,int disc)
{
float total,disamt,priceperdisc;
disamt = 12.99*(disc/100);
priceperdisc = 12.99 -(disamt);
total = priceperdisc*num;
printf("Receipt ");
printf("Disc Type: Golf Disc Quantity : %d Price per Disc : %f Total : %f ,num,priceperdisc,total");
return 0;
}
int main() {
char disctype;
intt num;
printf("Enter disc type u or U for ultimate discs, g or G for disc golf ");
scanf("%c",&disctype);
printf("Enter an number of discs ");
scanf("%d", &num);
switch(disctype) {
case 'u':
case 'U':
if(num<=10)
{
calculateU(num,10);
}
else if(num<=20)
{
calculateU(num,15);
}
else if(num<=30)
{
calulateU(num,20);
}
else if(num>=31)
{
calculateU(num,25);
}
break;
case 'g':
case 'G':
if(num<=10)
{
calculateG(num,10);
}
else if(num<=20)
{
calculateG(num,15);
}
else if(num<=30)
{
calulateG(num,20);
}
else if(num>=31)
{
calculateG(num,25);
}
break;
default:
printf("ERROR: Unsupported Disc selected");
}
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.