I've been writing a program where you give a buyer company ID and product ID to a program and it'll give you the price based on company exclusive discounts and a few other discounts.
However, every time I test it (with the same inputs), I get a completely different answer, usually hundreds of times larger than my intended answer. I'm still new to C and programming so a lot of the methods I've been using in this program I've never done before.
#include <stdio.h>
char compID[30];
double discount;
char prodID[30];
int prodAmount = 0;
double productPrice;
double tax;
double totalprice = 0;
int main() {
char cont[2];
printf("What is your company ID? ");
scanf("%s", compID);
if (strcmp(compID, "BFSC") == 0) {
discount = 1;
tax = 1.1;
}
do {
int itemPrice;
printf("What is the idea of the product you'd like to purchase? ");
scanf("%s", prodID);
if (strcmp(prodID, "FENG") == 0) {
productPrice = 12124.50;
}
printf("How many? ");
scanf("%d", &prodAmount);
printf("Do you want to purchase another item? (y/n) ");
scanf("%s", &cont);
} while (cont == 'y' || cont == 'Y');
totalprice = prodAmount*productPrice*tax*discount;
printf("%d", &totalprice);
}
If i put BFSC as the company ID and FENG as the product ID, the answers i'm getting are 1 million plus, rather than 13336.95.