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

Char assigned value

P: 2
Hi guys .. My program is working however instead of putting the assigning f=='x' it must xl -- HOWEVER when i used xl the computation goes wrong .. what shoud i do .. THANKS in ADVANCE
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. char f;
  6. int s_price, disc, t_price;
  7. clrscr();
  8. printf(" \n\tEnter the Shirt Size (X,L,M,S): ");
  9. scanf("%c",&f);
  10. printf(" \n\tEnter the The Price of Shirt: ");
  11. scanf("%d",&s_price);
  12.  
  13.  
  14. if (f=='x' && s_price>=500)
  15.         t_price=s_price+100;
  16. if (f=='x' && s_price<500)
  17.         t_price=s_price;
  18. if (f=='l' && s_price>=400)
  19.         t_price=s_price+50;
  20. if (f=='l' && s_price<400)
  21.         t_price=s_price+0;
  22. if (f=='m' || f=='s'&& s_price>0)
  23.         t_price=s_price+0;
  24.  
  25.  
  26. {
  27.  if (f=='x' && s_price>=500)
  28.     printf(" \n\n\tThe Discount is : 100");
  29. else if (f=='x' && s_price<500)
  30.     printf(" \n\tNo Discount ! Purchase atleast 500php ");
  31. else if (f=='l' && s_price>=400)
  32.     printf(" \n\n\tThe Discount is : 50");
  33. else if (f=='l' && s_price<400)
  34.     printf(" \n\tNo Discount ! Purchase atleast 400php ");
  35. else if (f=='m' || f=='s')
  36.     printf(" \n\tThe Discount is only for XL and Large Shirts ");
  37. }
  38.         printf(" \n\n\tThe Total Price is: %d",t_price);
  39. getch();
  40. }
Feb 26 '17 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 2,396
Is your question "why can't I make the program accept and recognize an input of "XL"?
  • XL is a string not a single character.
  • Need to declare f as a char array Instead of a char.
  • Need the scanf format to be "%s" instead of "%c".
  • Need to use strcmp instead of ==.
Additionally, you may want to make your input processing case-insensitive.
Feb 26 '17 #2

Post your reply

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