By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

help me for this problem

P: 7
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
Nov 15 '08 #1
Share this Question
Share on Google+
12 Replies


Expert 10K+
P: 11,448
I want it in C Language not C++
Do you want fries with that? We don't supply code for free here.

Jos (moderator)
Nov 15 '08 #2

P: 7
please l want your help ??
Nov 16 '08 #3

Expert 100+
P: 671
please l want your help ??
We can help. We just won't do other people's work outright. You get why, right?
Nov 16 '08 #4

P: 7
l only beging to C langauge and l want to learn how do it the all
and thanks
Nov 16 '08 #5

Expert 10K+
P: 11,448
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
Nov 16 '08 #6

P: 7
l have stop here l can't contening please help:
-------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. # include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int Pepsi , Sprite, Shani, Fanta,KD,a;
  6. printf("Please enter how much money you have in KD:\n");
  7. scanf ("%d",&KD);
  8. printf("Please choose your beverage:\n");
  9. printf("For Pepsi press 1\n");
  10. printf("For Sprite press 2\n");
  11. printf("For Shani press 3\n");
  12. printf("For Fanta press 4\n");
  13. scanf ("%d",&a);
  14.  
  15. if  (a=1)
  16. printf ("You have chosen Pepsi\n ");
  17. else if  (a=2)
  18. printf ("You have chosen Sprite\n ");
  19. else if  (a=3)
  20. printf ("You have chosen Shani\n ");
  21. else if  (a=4)
  22. printf ("You have chosen Fanta\n ");
  23.  
  24.  
  25. return 0;
  26. }
  27.  
  28.  
----------------------------------------------------------------------
And thanks
Nov 16 '08 #7

Expert 10K+
P: 11,448
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
Nov 16 '08 #8

P: 7
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
Nov 16 '08 #9

Expert 100+
P: 671
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.
Nov 17 '08 #10

P: 7
l have stop here l can't contening please help:
--------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. # include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int Pepsi,Sprite,Shani,Fanta,a,x,b,c;
  6. float KD;
  7. Pepsi==Sprite==Shani==Fanta==0.100;
  8. printf("Please enter how much money you have in KD:\n");
  9. scanf ("%f",&KD);
  10. if(KD>=0.100)
  11. {
  12. printf("Please choose your beverage:\n");
  13. printf("For Pepsi press 1\n");
  14. printf("For Sprite press 2\n");
  15. printf("For Shani press 3\n");
  16. printf("For Fanta press 4\n");
  17. scanf ("%d",&a);
  18. if  (a==1)
  19. printf ("You have chosen Pepsi\n ");
  20. else if  (a==2)
  21. printf ("You have chosen Sprite\n ");
  22. else if  (a==3)
  23. printf ("You have chosen Shani\n ");
  24. else if  (a==4)
  25. printf ("You have chosen Fanta\n ");
  26. }
  27. else if(KD<0.100)
  28. printf("enter the correct money you have in KD");
  29.  
  30. x=KD-0.100;
  31. if(x>=0.100)
  32. {
  33. printf("Would you like to buy another beverage?\n Yes =Press 1, No =press 2");
  34. scanf("%d",&c);
  35. if(c==1)
  36. continue;
  37. else if(c==2)
  38. break;
  39. }
  40. else if(KD==0.000)
  41. printf("You have 0.000 KD left in your account\n");
  42. printf("You do no have enough money to buy a single beverage bottle GOOD BYE");
  43.  
  44. return 0;
  45. }
  46.  
  47.  
-------------------------------------------------------------
And thanks
Nov 24 '08 #11

boxfish
Expert 100+
P: 469
Pepsi==Sprite==Shani==Fanta==0.100;
You need to use assignment operators here:
Pepsi=Sprite=Shani=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.
Nov 24 '08 #12

P: 7
Thank for answer
but can you but Example
Nov 24 '08 #13

Post your reply

Sign in to post your reply or Sign up for a free account.