Thread: Help for a beginner

  1. #1
    Registered User
    Join Date
    Oct 2020
    Posts
    16

    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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Post your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2020
    Posts
    16
    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

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Try something like
    Code:
    if ( ItemChosen == 'O' ) {
      if ( Orange <= budget ) {
      }
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2020
    Posts
    16
    Would this piece of code need to be done for All the fruits with multiple decisions?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Question -- From Absolute Beginner's Guide to C
    By Dghelerter in forum C Programming
    Replies: 5
    Last Post: 12-26-2013, 01:30 PM
  2. Beginner!!! Please help
    By reemaambekar in forum C Programming
    Replies: 66
    Last Post: 12-18-2008, 02:01 PM
  3. Beginner...
    By Devil Panther in forum Game Programming
    Replies: 38
    Last Post: 04-20-2004, 08:08 PM
  4. help a beginner
    By psychopath in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2004, 12:47 PM
  5. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM

Tags for this Thread