Hi guys,

Okay so lets say I've got a functions program that asks the user for a product quantity, the cost to make the product, and the selling price of the product. I want to make a function called total() to receive either the quantity and cost, or the quantity and price, and return the total. The total() function will be used to calculate the total cost and total price, but how do I write it so it will accept two different arguments like that?

Looking forward to your help!

Thanks!

K so in case people are confused I'm just going to post the whole code. The only thing I can't figure out is the total() function, but I'm sure you will find other little errors in there as well, because I am not totally done proofing it. Here it is:

#include <stdio.h>
#include <stdlib.h>

// ** Prototypes **
void heading(void);
int menu();
double add();
double getint(int min, int max, char prompt[]);
double getreal(double min, double max, char prompt[]);
double total();
double show(int prodnum, int prodtype, int prodquan, double cost, double price, 
	 double prod_price, double prod_cost, double prod_profit);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);
void message(char msg[]);


// ** Functions **
int main()
{
	int TRUE = 1;
	int FALSE = 0;
	int select, more = TRUE;

do
   {
	   
	select = menu();
	switch (select)
		{
	case 1: add(); break;
	case 2:
	case 3:
	case 4:
	case 5: more = quit(); break;
	default: message("\n\nPlease make a selection between 1 and 5.\a");
	}
   }
	
while (more);
return 0;
}
/*  ================================================================  */

int menu()
{
	int choice;

printf("Sierra Sporting Goods\n\n");
printf("1  =  Add a record\n");
printf("2  =  Report\n");
printf("3  =  Delete a record\n");
printf("4  =  Change a record\n");
printf("5  =  Quit\n");
choice = menuerror(1, 5, "Enter your selection: ");

return(choice);
}
/*  ================================================================  */

void heading()
{
system("cls");
printf("Sierra Sporting Goods\n\n\n");
return;
}
/*  ================================================================  */

double add()
{
	double cost, price, total, prod_cost, prod_price, prod_profit;
	double total_price, total_cost, total_profit;
    double MINCOST = 5.00;
	double MAXCOST = 900.00;
	double MINPRICE = 6.00;
	double MAXPRICE = 1000.00;
	int prodnum, prodtype, prodquan, count;
	int MINPROD = 1;
	int MAXPROD = 9999;
	int MINTYPE = 1;
	int MAXTYPE = 5;
	int MINQUAN = 1;
	int MAXQUAN = 50;
	char choice;

system("cls");
do
	{
   heading();
   prodnum = getint(MINPROD, MAXPROD, "product number");
   prodtype = getint(MINTYPE, MAXTYPE, "product type");
   prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
   cost = getreal(MINCOST, MAXCOST, "product cost");
   price = getreal(MINPRICE, MAXPRICE, "product price");
	prod_price = price * prodquan;
	prod_cost = cost * prodquan;
	prod_profit = (price - cost) * prodquan;

	total_price += prod_price;
	total_cost += prod_cost;
	total_profit += prod_profit;
   show(prodnum, prodtype, prodquan, cost, price, prod_price, prod_cost, prod_profit);
   choice = prompt("Continue");
   }
while (choice == 'Y');
}
/*  ================================================================  */

int getint(int min, int max, char item[])
{
	int x;
	printf("Enter a %s between %d and %d: ", item, min, max);
	scanf("%d%*c", &x);
	while (x < min || x > max)
	{
		message("\nError in range\a");
		printf("Enter a %s between %d and %d: ", item, min, max);
		scanf("%d%*c", &x);
	}
	return(x);
}
/*  ================================================================  */

double getreal(double min, double max, char item[])
{
	int y;
	printf("Enter a %s between %d and %d: ", item, min, max);
	scanf("%d%*c", &y);
	while (y < min || y > max)
	{
		message("\nError in range\a");
		printf("Enter a %s between %d and %d: ", item, min, max);
		scanf("%d%*c", &y);
	}
	return(y);
}
/*  ================================================================  */

double total(double quantity, double )
{
prod_price = 
prod_cost = 
}
/*  ================================================================  */

show(int prodnum, int prodtype, int prodquan, double cost, double price, 
	 double prod_price, double prod_cost, double prod_profit)
{
printf("\n\n\nSierra Sporting Goods\n\n");

printf("The product number is ---->  %04d\n", prodnum);
printf("The product type is ------>  %d\n", prodtype);
printf("The quantity is ---------->  %d\n", prodquan);
printf("The cost is -------------->  %.2lf\n", cost);
printf("The price is ------------->  %.2lf\n\n", price);

printf("Total product price ------> %.2lf\n", prod_price);
printf("Total product cost -------> %.2lf\n", prod_cost);
printf("Total product profit -----> %.2lf\n\n", prod_profit);

return 0;
}
/*  ================================================================  */

Ok now I'm having a problem getting the program to work in general. ARRGGHH!!! I tried to run it without the total() function to see if it works and the errors I still get are:

#1 error C2371: 'getint' : redefinition; different basic types (on line 114)

#2 error C2371: 'show' : redefinition; different basic types (on line 151)

Thought I had this one in the bag but apparently not! Please help me get this thing working!

This article has been dead for over six months. Start a new discussion instead.