-
Help for a beginner
Hi, I am brand new to programming and I am just getting to grips with C language. However, I am stuck! I have been ask to do a program which expects me to allow a customer to selected a piece of fruit from a shopkeepers menu. However, I am stuck on when the customer chooses the fruit (so enters a char data type) how I can then get the program to recognise the price of the fruit (As an integer) which the shopkeeper has entered to then be able to put this into a decision to then compare with the customers budget.
-
-
Code:
#include <stdio.h>
int main()
{
int Orange;
int Apple;
int Pear;
int Budget;
char ItemChosen;
printf("Please enter the price of oranges :");
scanf_s("%d", &Orange);
printf("Please enter the price of Apples :");
scanf_s("%d", &Apple);
printf("Please enter the price of Pears :");
scanf_s("%d", &Pear);
printf("**************************************\n");
printf("Hello and welcome to my fruit shop\n");
printf("Please enter your budget : ");
scanf_s("%d", &Budget);
printf("**************************************\n");
printf("Shop Menu : \n");
printf("Item: Price:\n");
printf("O: %d\n", Orange);
printf("A: %d\n", Apple);
printf("P: %d\n", Pear);
printf("**************************************\n");
printf("Please type what item of fruit you would like to purchase : ");
scanf_s(" %c", &ItemChosen, 1);
// I am not sure how to get the integer from the fruit the customer selects
if ( <= Budget)
{
printf("Your purchase has been successful\n");
printf("Purchase details\n");
printf("---------------------------------\n");
printf("Item selected : %c\n", ItemChosen);
printf("item price : %d", );
}
else if ( > Budget);
{
printf("Error Your budget has insignificant funds\n");
printf("Thanks for shopping with us!");
}
return 0;
if there is any other faults in the code please make me aware :)
-
Try something like
Code:
if ( ItemChosen == 'O' ) {
if ( Orange <= budget ) {
}
}
-
Would this piece of code need to be done for All the fruits with multiple decisions?