Hi guys, ok so I'm trying to figure this thing with functions out and I've been sitting here for seriously 6 hours with half of it done. I am so confused, please 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 total(double ticketquan, double ticketcost);
void show(double ticketquan, double ticketcost, double total, double grandtotal);
int contyn(char msg[]);
int main()
{
double ticketcost, ticketquan, total, grandtotal, costmin;
int quanmin;
char choice;
do
{
heading();
ticketquan = getfloat("quantity", quanmin);
ticketcost = getfloat("price", costmin);
total = total(ticketquan, ticketcost);
grandtotal = grandtotal(total);
show(ticketquan, ticketcost, total, 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 dbl;
do
{
printf("\nEnter a ticket %s greater than or equal to %.0lf: ", item, min);
scanf("%lf%*c", &dbl);
err = (dbl < min) || (dbl > max);
if (err) error(min, max);
}
while (err);
return (dbl);
}
/* ================================================================ */
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);
}
/* ================================================================ */