help me for this problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MIIB1
    New Member
    • Nov 2008
    • 7

    help me for this problem

    I want it in C Language not C++
    ----------------------------------------------------
    The beverages are:
    Pepsi , Sprite, Shani, Fanta
    --------------------------------------------------
    [The next example doesn’t show how the program handles the error caused by the user so
    as mentioned above be creative in handling the errors caused by the user]
    -------------------------------------------------------------
    Example out put of the program:
    Please enter how much money you have in KD:
    .2
    Please choose your beverage:
    For Pepsi press 1
    For Sprite press 2
    For Shani press 3
    For Fanta press 4
    1
    You have chosen Pepsi
    You have 0.100 KD left in your account
    Would you like to buy another beverage?
    Yes =Press 1, No =press 2
    1
    Please choose your beverage:
    For Pepsi press 1
    For Sprite press 2
    For Shani press 3
    For Fanta press 4
    2
    You have chosen Sprite
    You have 0.000 KD left in your account
    You do no have enough money to buy a single beverage bottle
    GOOD BYE
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by MIIB1
    I want it in C Language not C++
    Do you want fries with that? We don't supply code for free here.

    Jos (moderator)

    Comment

    • MIIB1
      New Member
      • Nov 2008
      • 7

      #3
      please l want your help ??

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #4
        please l want your help ??
        We can help. We just won't do other people's work outright. You get why, right?

        Comment

        • MIIB1
          New Member
          • Nov 2008
          • 7

          #5
          l only beging to C langauge and l want to learn how do it the all
          and thanks

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by MIIB1
            l only beging to C langauge and l want to learn how do it the all
            and thanks
            Show us what you have tried yourself and maybe we can help you with it.

            kind regards,

            Jos

            Comment

            • MIIB1
              New Member
              • Nov 2008
              • 7

              #7
              l have stop here l can't contening please help:
              -------------------------------------------------------------------
              Code:
              # include<stdio.h>
              
              int main()
              {
              int Pepsi , Sprite, Shani, Fanta,KD,a;
              printf("Please enter how much money you have in KD:\n");
              scanf ("%d",&KD);
              printf("Please choose your beverage:\n");
              printf("For Pepsi press 1\n");
              printf("For Sprite press 2\n");
              printf("For Shani press 3\n");
              printf("For Fanta press 4\n");
              scanf ("%d",&a);
              
              if  (a=1)
              printf ("You have chosen Pepsi\n ");
              else if  (a=2)
              printf ("You have chosen Sprite\n ");
              else if  (a=3)
              printf ("You have chosen Shani\n ");
              else if  (a=4)
              printf ("You have chosen Fanta\n ");
              
              
              return 0;
              }
              ----------------------------------------------------------------------
              And thanks

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Here's a C 101 hint: if you want to compare something to be equal to something
                else use the '==' operator, not the '=' operator (two equals signs instead of one).

                kind regards,

                Jos

                Comment

                • MIIB1
                  New Member
                  • Nov 2008
                  • 7

                  #9
                  thanks for the hint but
                  l have problem in this parts:
                  ----------------------------------------
                  You have 0.100 KD left in your account

                  Would you like to buy another beverage?
                  Yes =Press 1, No =press 2
                  1
                  ----------------------------------------
                  You have 0.000 KD left in your account
                  ------------------------------------------------------
                  how the program now this becose l
                  can't salove it
                  And thanks

                  Comment

                  • oler1s
                    Recognized Expert Contributor
                    • Aug 2007
                    • 671

                    #10
                    Write coherently. Post relevant code. Describe the problem in entirety. If there is unexpected output, state what you expected instead as well.

                    The code above clearly doesn't map to the output you have. So until you post relevant code, we cannot help you.

                    Comment

                    • MIIB1
                      New Member
                      • Nov 2008
                      • 7

                      #11
                      l late sorry

                      l have stop here l can't contening please help:
                      --------------------------------------------------------------------------
                      Code:
                      # include<stdio.h>
                      
                      int main()
                      {
                      int Pepsi,Sprite,Shani,Fanta,a,x,b,c;
                      float KD;
                      Pepsi==Sprite==Shani==Fanta==0.100;
                      printf("Please enter how much money you have in KD:\n");
                      scanf ("%f",&KD);
                      if(KD>=0.100)
                      {
                      printf("Please choose your beverage:\n");
                      printf("For Pepsi press 1\n");
                      printf("For Sprite press 2\n");
                      printf("For Shani press 3\n");
                      printf("For Fanta press 4\n");
                      scanf ("%d",&a);
                      if  (a==1)
                      printf ("You have chosen Pepsi\n ");
                      else if  (a==2)
                      printf ("You have chosen Sprite\n ");
                      else if  (a==3)
                      printf ("You have chosen Shani\n ");
                      else if  (a==4)
                      printf ("You have chosen Fanta\n ");
                      }
                      else if(KD<0.100)
                      printf("enter the correct money you have in KD");
                      
                      x=KD-0.100;
                      if(x>=0.100)
                      {
                      printf("Would you like to buy another beverage?\n Yes =Press 1, No =press 2");
                      scanf("%d",&c);
                      if(c==1)
                      continue;
                      else if(c==2)
                      break;
                      }
                      else if(KD==0.000)
                      printf("You have 0.000 KD left in your account\n");
                      printf("You do no have enough money to buy a single beverage bottle GOOD BYE");
                      
                      return 0;
                      }
                      -------------------------------------------------------------
                      And thanks

                      Comment

                      • boxfish
                        Recognized Expert Contributor
                        • Mar 2008
                        • 469

                        #12
                        Pepsi==Sprite== Shani==Fanta==0 .100;
                        You need to use assignment operators here:
                        Pepsi=Sprite=Sh ani=Fanta=0.100 ;

                        if(KD>=0.100)
                        If you want the user to be able to select beverages multiple times, use a loop:
                        while(KD>=0.100 )

                        else if(KD==0.000)
                        else if won't work here; use if:
                        if(KD==0.000)

                        I'm sure there is more that needs to be fixed, but I hope this will help somewhat.

                        Comment

                        • MIIB1
                          New Member
                          • Nov 2008
                          • 7

                          #13
                          Thank for answer
                          but can you but Example

                          Comment

                          Working...