473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Char assigned value

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
1 1090
donbock
2,426 Expert 2GB
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

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

Similar topics

4
by: Don | last post by:
Using PHP, I'm creating an <input> tag. How do you delimit the text string for the value parm of an <input> tag, when the string contains the delimit char? Example: <input...value="This text...
5
by: DJTB | last post by:
Dear Group, I'd like to check if a value is defined in an enum. Example: ------------------------------------------------------ typedef enum { A_VALUE = 1,
2
by: Gidi | last post by:
Hi, I'm writing a C# win application program, and i need to transfer my hebrew letters from unicode to ascii, now if i use the ascii encoding it writes me ??? instead of the hebrew letter i've...
3
by: Cindy | last post by:
ASP.NET - C# (User Control) I have a drop-down as usercontrol. In the user control's Page_Init , the drop down gets populated. The SelectedItem.Text is retrived using property get The...
5
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as...
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
1
by: veblen.lee | last post by:
for an example: 'a' value 0x61 '1' value 0x31.
2
by: Dica | last post by:
i need to pass special characters to my application in the extended ascii range. however, anything above 127 fails when i try like this: (char)184. unsigned char should be able to do this in...
0
by: coolvivek33 | last post by:
hi i am facing a strange problem i am trying to build report using sql server 2005 and microsoft visual studio2005 now it is in requirement that i should seperate date from time.I have done that...
16
by: Virtual_X | last post by:
if we use char in a function parameter like that void st(char x) {cout << x;} and char* as a parameter in the same function instead of char x what would be different in my experiments i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.