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);
}
/* ================================================================ */

A few things. One, you are in the C++ forum. This is a C program so you should probably repost over there.

Two, you don't want to name your variables the same name as your functions. It's too easy for the compiler (and people) to get confused by which you mean. So functions like this:

total = total(ticketquan, ticketcost);

should be renamed so that there is no confusion between the variable "total" and the function "total".

In this function call:

grandtotal = grandtotal(total);

you are passing the function grandtotal a parameter, but your function specification takes no parameters:

double grandtotal();

So change a few variable names so that they don't match the function names, and take care of the above function call parameter mismatch, and several of your errors will go away.

OMG wow... Thanks for enlightening me. I was wondering why I've been having such an incredibly difficult time with all of this, and I just realized that my class is C Programming and I accidentally got the C++ Primer Plus book instead of the C Primer Plus book. Jeez I feel like a total idiot. Thanks for the help though!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.