Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with code

Status
Not open for further replies.

vacantstare

Technical User
Nov 16, 2004
6
US
for some reason this program refuses to compile, all the errors seem to occur on the &quot;Dsicount&quot; function when i can`t see any, any comments ideas would be greatly appreciated #include <stdio.h>

//funtion prototypes
void Cost_of_Purchase(float *pcost); //enter price of items
float Discount(float *pcost); //discount using required percentage
void Output_Bill(float,float); //output final values
void HoldScreen(void);

#define disc_1 = 0.08;
#define disc_2 = 0.10;
#define Limit = 100;



void main (void)
{
//declare variables
float cost;
float discounted_amount;

Cost_of_Purchase(&cost);
discounted_amount = Discount(&cost);
Output_Bill(cost, discounted_amount);
Holdscreen();

}


//input costs
void Cost_of_Purchase(float *pcost)
{
float price;
float cost;
int qty;

puts(&quot;Enter the following for item required&quot;);
printf(&quot;\tPrice of item&quot;);
scanf(&quot; %d&quot;, price);
printf(&quot;Quantity required&quot;);
scanf(&quot; %d&quot;, qty);
cost = qty * price;
}

//discount
float Discount(float *pcost)
{
float amount;
if (*pcost <= Limit)
amount = disc_1 * *pcost;
else
amount = disc_2 * *pcost;
return amount;
}

//output relavant amounts
void Output_Bill(float cost, float discounted_amount)
{
float discounted_cost;
discounted_cost = cost - discounted_amount;
printf(&quot;Cost of goods purchased....%10.2d&quot;, cost);
printf(&quot;Amount of discount....%10.2d&quot;, discounted_amount);
printf(&quot;Cost of goods purchased....%10.2d&quot;, discounted_cost);
}

void HoldScreen(void)
{
printf(&quot;\n\n\tPress ENTER to finish&quot;);
fflush(stdin);
getchar();
}


 
Your define section is the problem. You should change it as follows:

#define disc_1 0.08
#define disc_2 0.10
#define Limit 100

If you say: #define disc_1 = 0.08; then wherever disc_1 is met by the compiler, it is replaced with = 0.08; which you don't really want.

Danny.

 
NOw it says that there is an illegal else without matching if!! i`m sure this is right below



float Discount(float *pcost)
{
float amount;
if (*cost <= Limit)
amount = *pcost * disc_1;
else
amount = *pcost * disc_2;
return amount;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top