Hello again! Today's problem is one that is bothering me. My research into it has once again gone to waste, so I hope somebody here can help me understand why this is happening. The problem is everything is working honky dory, however I find myself having to enter the same command up to 3 times to get it to register. How do I make the program more efficient so I only have to enter a command once?
#include <stdio.h>
#define MAX 105 /*what the pop price is in cents*/
#define MIN 5
char c;
int leftover=POPPRICE; //
int value; // what was entered
void entryChecker (char c)
{
if (c=='d' || c=='D'){
printf("Dime detected!");
c='\0';}
else if (c=='q' || c=='Q'){
printf("Quarter detected!");
c='\0';}
else if (c=='n' || c=='N'){
printf("Nickel detected!");
c='\0';}
else if (c=='r' || c=='R'){
printf("Returning money!");
c='\0';}
else{
printf("That was not a valid command.");}
}
int main(int argc, char *argv[])
{
value=atoi(argv[1]);
if ((value % 5) != 0&&value<=MAX&&value>=MIN)
{
printf("Please enter a number of multiples of 5\n");
printf("Make sure the price is between 5 - 105 cents\n");
}
else
{
printf("The price of pop is %d, cents\n", value);
printf("Please insert any combination of nickels [N or n],\n");
printf("dimes [D or d] or quarters [Q or q].\n");
printf("You can also return your money to you by pressing R or r\n");
printf("%d",value);
while ((c=getchar())!='e' && (c=getchar())!='E')
{
scanf("%c",&c);
entryChecker (c);
}
}
}
Once again, I deeply appreciate any assistance thrown my way.
EDIT: I also realize using atoi is not the best way to handle this, however for time constraints it's what i'm using now.