[b]THIS IS MY CODE SO FAR CAN SOMEONE HELP ME CORRECT IT?
#include<stdio.h>
main ()
{
int order_num,product_code, quantity_on_order, quantity_in_stock, reorder_total;
char product_name, ;
float product_price, credit_limit, gross_total, discount_amount, net_total, cash, change;
order_num=1;
quantity_in_stock=20;
reorder_total=0;
printf("Enter the name of the product\n");
scanf("%s", &product_name);
printf("Please enter the product code\n");
scanf("%d", &product_code);
{
printf("Please enter the number of products on order\n");
scanf("%d", &quantity_on_order);
if (quantity_in_stock>=quantity_on_order)
printf("QUANTITY ON ORDER IS IN STOCK\n");
else
printf("QUANTITY ON ORDER IS OUT OF STOCK\n");
}
{
printf("Enter the customer's credit limit\n");
scanf("%f", &credit_limit);
printf("Enter the price of the product\n");
scanf("%f", &product_price);
if (credit_limit>=product_price)
printf("CREDIT LIMIT OK\n");
else
printf("CREDIT LIMIT EXCEEDED\n");
}
{
int choice;
printf("PLEASE FOLLOW THE PRECEEDING INSTRUCTIONS AND SELECT THE APPROPRIATE CHOICE\n");
printf("PRESS 1 for: Quantity on order IN STOCK and credit limit OK\n");
printf("PRESS 2 for: Quantity on order IN STOCK and credit limit EXCEEDED\n");
printf("PRESS 3 for: Quantity on order OUT OF STOCK and credit limit OK\n");
printf("PRESS 4 for: Quantity on order OUT OF STOCK and credit litmit EXCEEDED\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
gross_total=quantity_on_order*product_price;
{
if (order_num<=10)
discount_amount=gross_total*(10/100);
else
discount_amount=gross_total*(5/100);
}
net_total=gross_total-discount_amount;
printf("Enter the amount of cash received\n");
scanf("%f", &cash);
change=cash-net_total;
printf("RECIEPT\n");
printf("Order Number:%d\n", order_num);
printf("Product Bought:%s\n", &product_name);
printf("Product Code:%d\n", product_code);
printf("Product Price:%f\n", product_price);
printf("Quantity ordered: %d\n", quantity_on_order);
printf("Gross total:%f\n", gross_total);
printf("Discount amount:%f\n", discount_amount);
printf("Net total:%f\n", net_total);
printf("Cash:%f\n", cash);
printf("Change:%f\n", &change);
++order_num;
reorder_total=reorder_total+quantity_on_order;
break;
case 2:
printf("The quantity being ordered is IN STOCK but credit limit has been EXCEEDED!\n");
printf("PLEASE RESTART AND ENTER A NEW CREDIT LIMIT!\n");
break;
case 3:
printf("Quantity on order OUT OF STOCK, do you want to continue?");
break;
case 4:
printf("The quantity being ordered is OUT OF STOCK and credit limit has been EXCEEDED!\n");
break;
default:
printf("THE CHOICE ENTERED IS INVALID\n!");
printf("PLEASE START OVER AND ENTER A NUMBER BETWEEN 1 AND 4");
}
I have but its not the syntax errors that are the prolem right now. I need to add data structures and functions etc. Problem is i dont really know how to. That's why im asking for some help.
Create some abstraction, divide your variables in 3 structures, stock, product, order, after that, create some functions to compute an order, stock operations, display lists of products available, etc. and make a nice menu for your application.
I am one that thinks that whoever thought up the concept of percentage did so after getting repeatedly hit in the head.
Why are you multiplying by 10/100? Why not by 100/1000 or 1000/10000? Or by .1, which is the second most straightforward way? The most straightforward way is dividing by 10, just like the most straightforward way of saying "the 5% of x" is "x divided by 20".
Programmers never use percentages except for dealing with users. If we need to represent a fraction of something, 1 will be the whole, .5 the half, .25 the quarter, and so on. Likewise, 1.1 will be "the whole and one tenth".
so the division is no longer the problem now. can someone tell me how to put in a yes/no selection and get the program to terminate if the answer is no, or continue if yes, then end when the "yes" condition is finished?
case 3:
char ans;
printf("Quantity on order OUT OF STOCK, do you want to continue y/n?");
scanf("%s", &ans);
if (ans=='y')
{
gross_total=quantity_on_order*product_price;
if (order_num<=10)
discount_amount=gross_total*10/100;
else
discount_amount=gross_total*5/100;
net_total=gross_total-discount_amount;
printf("Enter the amount of cash received\n");
scanf("%f", &cash);
change=cash-net_total;
printf("RECIEPT\n");
printf("Order Number:%d\n", order_num);
printf("Product Bought:%s\n", &product_name);
printf("Product Code:%d\n", product_code);
printf("Product Price:%0.2f\n", product_price);
printf("Quantity ordered: %d\n", quantity_on_order);
printf("Gross total:%f\n", gross_total);
printf("Discount amount:%0.2f\n", discount_amount);
printf("Net total:%0.2f\n", net_total);
printf("Cash:%0.2f\n", cash);
printf("Change:%0.2f\n", change);
++order_num;
reorder_total=reorder_total+quantity_on_order;
}
else
printf("Thank you for visiting MORE DISCOUNTS SPORTS STORE,");
printf("The product you have ordered is out of stock please come again");
break;