I'm a First year IT student
and I'm having a
problem with my
vending machine program..

I can't subtract the cost from the input of the user..
can anyone help me with this simple problem?..


struct vendingmachine
	int x,y;
	float cost;
	double change;
	char nikz;
int a,b,h;
float x =1.75,y =1.90,change;
struct vendingmachine nikz[10];
printf("========================   Vending Machine of Errors   ==========================");
	printf("Drinks name\t		Cost	        Stock in the machine\n\n\n");
	printf("1. Cream soda\t 		1.75$\t		20\n");
	printf("2. Grape Soda\t		1.75$\t		15\n");
	printf("3. Cola\t			1.75$\t		20\n");
	printf("4. Lemon-lime\t		1.90$\t		18\n");
	printf("5. Root-beer\t		1.90$\t		20\n\n");
	printf("6. Do you wish to Exit the Program? \n \n \n");

printf("Your choice is   :\t");

	printf("You have chosen Cream soda\n");
	{printf("You have chosen Grape soda\n");}
	{printf("You have chosen Cola\n");}
	{printf("You have chosen Lemon-lime\n");}
	{printf("You have chosen Root-beer\n");}
	{printf("Thank you come again\n\n\n");
	return 1;}
printf("\nEnter your deposit:\t");
printf("Your change is %f");

Line 18...Why do you have a brace there?

Also line 55

printf("Your change is %f" );

What are you printing? Where is the float variable?

Edited 6 Years Ago by gerard4143: n/a

shetnok13> I can't subtract the cost from the input of the user..[.]

Logic dictates that you must know how much it cost the choice of beverage. After that you need the amount payed, supposedly it would have been entered into variable `b' (you wrote: scanf("%d",&b); ) then you compare to see if it was more or less or equal to the amount necessary.
After that you subtract price (either 1.75 or 1.90) from `b' if the amount entered was more than exact.

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