I am seriously so bummed out right now, and I feel like a complete idiot. I have been sitting here for seriously 7 hours now trying to figure out how to do this program, and the book I have for the class has been of no help whatsoever. I posted my problem in C++ and had someone tell me that this is a C Program, so after a minute I looked at my course website and the book and realized that the reason the book makes no sense at all is that it is C++ Primer Plus, instead of C Primer Plus. I am so upset because I have been working on this assignment for so long, and it's due at midnight tonight, and I feel like I just set myself back really far. If anyone would be willing to help me I would appreciate it so much. I've understood every other thing I've learned in C so far (printf, scanf, validation, calculations, etc.) but I can't figure out how to write these functions, and now I don't even have the right book to look in. I know the assignment isn't too difficult because all of the assignments before this have been fairly easy for me. I just really need some help!
The program is to track the amount and price of raffle tickets sold, and then add to a grand total. The price per raffle ticket has to be equal to or greater than $5.00, amount of tickets has to be equal to or greater than 0.
I've planned the program out to hopefully look like this at the end--
WELCOME TO THE RAFFLE!
Enter price per raffle ticket (must be at least $5.00):
Enter number of raffle tickets (must be at least 0):
Number of tickets ---------->
Price per ticket ------------->
Total amount due ---------->
Would you like to make another raffle ticket purchase? (y/n)
/* If y, loop back to beginning. If n, proceed to next. */
Total cost of all tickets ---->
/*==============================================*/
Can someone please help me with this? I know it's not that difficult but I'm totally lost and so exhausted! Here is the code I've written so far:
/* ================================================================== */
/* > Program: Exam1.c < */
/* > < */
/* > Description: printf, scanf, loop < */
/* > < */
/* > Name Date Comment < */
/* > ------------- -------- ------------------------------ < */
/* > Janelle Wood 2/27/08 Author < */
/* ================================================================== */
#include <stdio.h>
#include <stdlib.h>
void heading(void);
void error(double min, double max);
double getfloat(char prompt[], double min);
double grandtotal(double tickettotal);
double total(double ticketquan, double ticketcost);
void show(double ticketquan, double ticketcost, double tickettotal, double grandtotal);
int contyn(char msg[]);
int main()
{
double ticketcost, ticketquan, tickettotal, grandtotal, costmin;
int quanmin;
char choice;
do
{
heading();
ticketquan = getfloat("quantity", quanmin);
ticketcost = getfloat("price", costmin);
tickettotal= total(ticketquan, ticketcost);
grandtotal = grandtotal(tickettotal);
show(ticketquan, ticketcost, tickettotal, grandtotal);
choice = contyn("\nWould you like to purchase more raffle tickets?");
}
while (choice == 'y' || choice == 'Y');
return 0;
}
/* ================================================================ */
void heading()
{
system("cls"); // Linux/Unix use: system("clear");
printf("WELCOME TO THE RAFFLE!");
return;
}
/* ================================================================ */
double getfloat(char item[], double min)
{
int err;
double ticketcost;
do
{
printf("\nEnter a ticket %s greater than or equal to %.0lf: ", item, min);
scanf("%lf%*c", &ticketcost);
err = (ticketcost < min);
if (err) error(min, max);
}
while (err);
return (ticketcost);
}
/* ================================================================ */
void error(double min, double max)
{
printf("\nOut of range, try %.0lf to %.0lf, press any key ", min, max);
return;
}
/* ================================================================ */
double total(double ticketnum, double ticketcost)
{
return (ticketnum * ticketcost);
}
/* ================================================================ */