1. ## Help with program-functions

I hope someone can help me. I think I'm on the right track but am missing a piece of the puzzle. I'm hoping, wishing (okay begging) someone to take a look at my program and provide me with some feedback. Please let me know if I'm completely off base or what.
The program is an invoice. The user inputs the invoice cost, then inputs the discount code. Based on the code used the discount rate is determined. Using a function I am to calculate the discount amount. The program should return the initial invoice cost, discount amount and final invoice cost.
Thanks,
Angela

Code:
```#include<stdio.h>

/* Program will calculate customer's discount based on code entered by user*/
/* At program's termination the initial invoice amount, discount amount and
final invoice cost will be display.*/

float Calc_Discount();
void Display_Results();

int main()
{
extern float initial_invoice_amount, discount_amount, final_cost;
extern char discount_code;

/*Display dicount percent with mathching code*/
printf("Discount code A = 5%%.\n");
printf("Discount code B = 8%%.\n");
printf("Discount code C = 12%%.\n");

/*User Input*/
printf("Input the customer's invoice amount:\n");
scanf("%f", & initial_invoice_amount);

printf("Input the customer's discount code:\n");
scanf("%c", &discount_code);

final_cost = (initial_invoice_amount - discount_amount);

Display_Results();

return 0;
}
Calc_Discount(discount_code)
{
if((discount_code='A') || (discount_code='a'))
{
discount_amount == (0.05*initial_invoice_amount);
}
return discount_amount;

if((discount_code='B') || (discount_code='b'))
{
discount_amount == (0.08*initial_invoice_amount);
}
return discount_amount;

if((discount_code='C') || (discount_code='c'))
{
discount_amount == (0.12*initial_invoice_amount);
}
return discount_amount;
}

void Display_Results(float initial_invoice_amount,float discount_amount, float final_cost)
{
printf("\nThe invoice charges are as follows:\n");
printf("\nInitial Invoice: %f", initial_invoice_amount);
printf("\nDiscount Amount: %f", discount_amount);
printf("\n--------------------------");
printf("\nFinal Cost: %f", final_cost);
}

}```

2. You're defining your functions inside of the 'main' function. This is wrong. Do this:
Code:
```float Calc_function( ...whatever... )
{
...code goes here...
}

void Display_function( ...whatever... )
{
...code goes here...
}

int main( void )
{
...code goes here...
...use functions here...
return 0;
}```
Each function is a seperate entity. They need to be declared out on their own. If this was a C++ class, it'd be different, but it's C, so do it as per above.

Quzah.

3. you have more { than }. fix your code so it shows what you intend for it to do.

4. In the function prototype

Code:
`float Calc_Discount();`
has no formal parameters

in the function definition
Code:
`Calc_Discount(discount_code)`
has one formal parameter. This is an error.

Also, why are you using extern with the variables, here you do not need them.

5. See if this hatchet job will be of any use. It's late and I'm tired, so things were cutback from your original post. Let's just hope the cutbacks weren't part of the programs purpose

Code:
```#include <stdio.h>
#include <ctype.h>

void showResults(float, double, double);
double calcDiscount(char, float);

int main(void)
{
float initialAmount;
double discountAmount, finalCost;

char discountCode;

printf("Discount code A = 5%%.\n");
printf("Discount code B = 8%%.\n");
printf("Discount code C = 12%%.\n");

printf("\nInput the customer's discount code: ");
scanf("%c", &discountCode);

printf("Input the customer's invoice amount: ");
scanf("%f", &initialAmount);

discountAmount = calcDiscount(discountCode, initialAmount);

finalCost = initialAmount - discountAmount;

showResults(initialAmount, discountAmount, finalCost);

return 0;

}

double calcDiscount(char code, float amount)
{

double total;

switch(toupper(code))
{
case 'A': total = 0.05 * amount;
break;

case 'B': total = 0.08 * amount;
break;

case 'C': total = 0.12 * amount;
break;

default: printf("\nThere is no such option for %c\n", code);
total = 0.0;
break;
};

}

void showResults(float amount1, double amount2, double amount3)
{
printf("\nThe invoice charges are as follows:\n");
printf("\nInitial Invoice: %.2f", amount1);
printf("\nDiscount Amount: %.2f", amount2);
printf("\n--------------------------");
printf("\nFinal Cost: %.2f", amount3);

}```
Good luck.

6. ## Thanks

Thanks everyone for the help. I really appreciate the feedback. Part of my problem is that I have a C++ book but the Instructor is teaching C. He told us that we would still be able to use the book we were told to buy. However, I'm having a hard time switching back and forth between the two.
Again thanks for the help.

Angela