Is there any other code written for a coke machine program.
We’ll start by having the user “insert” their money. Since they can’t physically insert the money, we will just ask them how much they wish to insert and we will keep track of how much money they have inserted. The money insertion will be handled in a SEPARATE function. For example, before they start, their total inserted is $0. let’s say that a drink costs $1.00. If they say that they are inserting “$0.25” then we will add $0.25 to $0 and tell them to please insert $0.75. Then we will ask them how much they are inserting. If they say “$0.25”, then we add $0.25 to the $0.25 that they have already inserted giving them $0.50. Once they have inserted $1.00, we can give them their drink options. If they have not entered at least $1.00, we will invoke the money function so they can insert more.
The above (money insertion) will typically be handled in a loop.
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.
Here is my code:
#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
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
if(totalinsert < money)
{
printf("\nPlease insert more money: ");
scanf("%f", &insert);
totalinsert = (insert + totalinsert);
}
if(totalinsert < money)
{
printf("\nPlease insert more money: ");
scanf("%f", &insert);
totalinsert = (insert + totalinsert);
}
if(totalinsert < money)
{
printf("\nPlease insert more money: ");
scanf("%f", &insert);
totalinsert = (insert + totalinsert);
}
if(totalinsert < money)
{
printf("\nPlease insert more money: ");
scanf("%f", &insert);
totalinsert = (insert + totalinsert);
}
if(totalinsert == money) //This is the same as the decision process as the statement before but this function evaluates if the statement is true to perform future function bypasses the other code functions
{
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);
totalinsert = (totalinsert == insert);
getchar();
}
if(drinkchoice == '1')
{
printf("here is your coke");
scanf("%c", &drinkchoice);
getchar();
}
if(drinkchoice == '2')
{
printf("here is your sprite");
scanf("%c", &drinkchoice);
getchar();
}
if(drinkchoice == '3')
{
printf("here is your Dr Pepper");
scanf("%c", &drinkchoice);
getchar();
}
int NumArray[10];
for(int counter = 0; counter < 10; counter ++)
{
printf{"\nPlease make your selection");
scanf("%d", soda);
NumArray[counter];
}
getchar();
return 0;
}