>I am just wondering if there is anyone else who have a simplier code willing to look at mine and give me some >pointers on making my code simplier using For loop, while loop, or if else loop.
Is this your code?.
Has you tried to compile it?. I know you could have not made it work.
This is not valid in C:
for(int counter = 0; counter < 10; counter ++)
{
printf{"\nPlease make your selection");
scanf("%d", soda);
NumArray[counter];
}
The counter variable can not be declared in the loop construction.
The variable soda is not declared anywhere.
However, that whole "for loop" doesn't do anything for your code.
printf("\nWhat would you like."); //This is a menu selection window allowing the user to make a selection after the correct amount of money is enterd
printf("\nPress 1 for coke\nPress 2 for sprite\nPress 3 for drpepper: ");
scanf("%c", &drinkchoice);
In this part you are asking the user for a pre-selected number that
map the kind of soda, but then you store it in a character variable.
That will never do. Check and you'll see that pattern in other parts
of the code you have posted.
Now you seems to know that to make it simpler a loop form is needed. Why don't you try first by yourself and then report again?.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
>dude please study c well before u start writing code u have used an if 4
>times wht if after 4th time money is still less use a dowhile loop
Wow, do you even know what punctuation is? We recommend that you use proper English. There's no reason to use chat abbreviations and poor grammar here. You have plenty of time to compose your post and make it correct. If you don't, you make things harder on non-native English speakers.
>and study a lot before u get to coding....
You can't learn C without writing code.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
#include <stdio.h>
int main()
{
char drinkchoice; //gives drinkchoice a named character to be recognized
float insert= 0.00; //This allows the insert function to be used throughout code
const float money = 1.00; //Same here as well as totalinsert function
float totalinsert = 0.00; //this allows the totalinsert function to be carried out as the insert function
printf("\nHow much do you wish to insert: "); //prompts the user for their amount
scanf("%f", &insert); //recieves input from user
while (totalinsert < money)
{
printf("\nPlease insert $", money-totalinsert);
scanf("%f", &insert);
totalinsert = (insert + totalinsert);
}
printf("You get back %f $!!!",money-totalinsert);
printf("\nWhat would you like."); //This is a menu selection window allowing the user to make a selection after the correct amount of money is enterd
printf("\nPress 1 for coke\nPress 2 for sprite\nPress 3 for drpepper: ");
scanf("%c", &drinkchoice);
switch (drinkchoice)
{
1:{printf("here is your coke");break;}
2:{printf("here is your sprite");break;}
3:{printf("here is your Dr Pepper");break;}
}
}
[/QUOTE]
Now, you can insert 0.00001$ too. Since money won't change in your program, you should declare it as constant.
Chaster
Junior Poster in Training
68 posts since Jun 2007
Reputation Points: 12
Solved Threads: 3