Hi guys I am looking to go through C then transition to C++ later this year. I am having a minor problem with switch statement and I am not in a position to ask anyone as there are no tech savvy that I know. So I thought it was better to ask here.
So I am trying to get input from the user with the switch statement, once the user has entered a letter for what he is looking to purchase, they should be summed up but they dont and they just increment all the last three input by 1 ( ie for artichokes, beets, and carrots). I hope that someone can show me what I am not seeing. Thanks!!!
// abcmail.c -- This is a program that calculates all fo ABC Mail Order Grocery activities
#define ARTICHOKE 2.05
#define BEET 1.15
#define CARROT 1.19
#include <stdio.h>
int main (void)
{
// Declaring my Variables
char ch; // Input character
int artichoke_count; // artichoke counter
int beet_count; // beet counter
int carrot_count; // carrot counter
// Initializing my variables
artichoke_count = 0;
beet_count = 0;
carrot_count = 0;
printf("Enter the letter a for artichoke, b for beet and c for carrot and q to quit: ");
while((ch = getchar()) != 'q' )
{
int _artichoke;
int _beet;
int _carrot;
if (islower(ch))
{
switch(ch)
{
case 'a':
{
printf("Enter the number of arhitokes you need: ");
scanf("%d", &_artichoke);
artichoke_count+=_artichoke;
break;
}
case 'b':
{
printf("Enter the number of beets you need: ");
scanf("%d", &_beet);
beet_count+=_beet;
break;
}
case 'c':
{
printf("Enter the number of carrots you need: ");
scanf("%d", &_carrot);
carrot_count+=_carrot;
break;
}
default:
printf("I am only accepting a for arhitokes, b for beets and c for carrots");
break;
} // end of switch
} // end of if
} // end of while loop
printf("You have entered %d artichokes, %d beets, and %d carrots", artichoke_count, beet_count, carrot_count);
return 0;
}