473,383 Members | 1,953 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,383 software developers and data experts.

C - How do you assign more than one char to a single case (switch function)

1
I figure this is a pretty basic question so I'll just show an excerpt from my small source file for an example, rather than uploading it.

I have WinXP32 Pro and DevC/C++.

Note that everything is declared, just not included. I want to know how to include upper and lowercase letters into the same function rather than repeat the whole case over and occupy more space. I tried to use || (or), it compiles but it assigned the uppercase Y to the default case instead.

"...
if(setoff=1) switch(yes_no)
{
case 'y' || 'Y' : printf("\nCare to make it interesting?\n\n Place bet in Canadian Dollars, no change: $");
scanf("%d", &bet); printf("\n1)Rock, 2)Paper, 3)Scissors\n"); scanf("%d", &rps);
..."

Thanks for any help.
Aug 31 '09 #1
3 2798
JosAH
11,448 Expert 8TB
You can use more than one case label:

Expand|Select|Wrap|Line Numbers
  1. switch (chr) {
  2.    case 'y':
  3.    case 'Y': // yes
  4.                 break;
  5.    case 'n':
  6.    case 'N': // no
  7.                 break;
  8. }
  9.  
kind regards,

Jos
Aug 31 '09 #2
donbock
2,426 Expert 2GB
By the way, "if(setoff=1)" is wrong. That assigns "1" to setoff and unconditionally takes the true path through the if-else statement.

There are two basic strategies:
  1. Test for both uppercase and lowercase letters.
  2. Convert the input to lowercase (or uppercase) and test only for letters of that case.
There are many ways to implement these strategies.
Aug 31 '09 #3
kkrish
3
Hi,

Instead of returning char values, it will be good to return int values like 0,1 etc;
Sep 2 '09 #4

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

Similar topics

6
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
54
by: zhaoyandong | last post by:
In one of my interview, some people asked me why C is faster C++, and tell me to illustrate at least two reasons. I can't find the answer in the web. I'll appreciate any suggestion on this....
2
by: Megan | last post by:
Hi everybody- I have 2 tables, Hearings and Rulings. Both have primary keys called, CaseID, that are autonumbers. I don't want both tables to have the same autonumber. For example, if Hearings...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
9
by: | last post by:
void show( char *s, ...) is a function seemd like prinf code -------------- #include <stdio.h> #include <stdarg.h> void show( char *s, ...) { va_list stage;
3
by: ehabaziz2001 | last post by:
I know one of the pointer benefit is that we can return more than one value from a function . The down program has an error that I can not discover . That is the call of the function : The Call:...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
2
by: wingleader | last post by:
Hi. Got such a problem. I wrote a url decoding programm. The main idea is, that programm take char by char from incoming string, decides what changes must be made, and then inserts them to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?

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.