473,396 Members | 1,683 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.

Adding values returned by different cases in switch

HI , Can u tell how to add the two values returned by two different fuctions in different cases of switches????
Sep 26 '07 #1
4 1595
Meetee
931 Expert Mod 512MB
HI , Can u tell how to add the two values returned by two different fuctions in different cases of switches????
What have you done so far? I can help you only if you have tried something on this issue. Also clearify about different cases of switches. I don't understand, you want switch case in individual functions or function that calculates addition.

Regards.

PS. Refer posting guidelines before posting. It is very helpful.
Sep 26 '07 #2
sicarie
4,677 Expert Mod 4TB
HI , Can u tell how to add the two values returned by two different fuctions in different cases of switches????
No. A switch statement is based on cases, where one case will execute and the others won't (if it's designed properly). However, if you did set it up so that your cases ran together (very, very bad form), you said the variables were returned.

So store them and add them.
Sep 26 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
if you did set it up so that your cases ran together (very, very bad form),
Not necessarily. I may happen that multiple cases have the same code. Like January, March, May, July, August,October and December all have 31 days:

Expand|Select|Wrap|Line Numbers
  1. switch (month)
  2. {
  3.    case January:
  4.    case March:
  5.    case May:
  6.    case July:
  7.    case August:
  8.    case October:
  9.    case December:
  10.            DaysInMonth = 31;
  11.            break;
  12. etc...
  13.  
Sep 26 '07 #4
sicarie
4,677 Expert Mod 4TB
Not necessarily. I may happen that multiple cases have the same code. Like January, March, May, July, August,October and December all have 31 days:

Expand|Select|Wrap|Line Numbers
  1. switch (month)
  2. {
  3.    case January:
  4.    case March:
  5.    case May:
  6.    case July:
  7.    case August:
  8.    case October:
  9.    case December:
  10.            DaysInMonth = 31;
  11.            break;
  12. etc...
  13.  
I see your point, weaknessforcats, but I would still think that such 'cascading' cases could probably be better dealt with in another fashion (such as in the specific example above, using a date class that can have some sort of 'getDaysInMonth()' method). Especially for writing easily-maintainable code that you can go back and make changes on without causing unintended effects, I would avoid them. I suppose that is more personal style, though.
Sep 26 '07 #5

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

Similar topics

5
by: Bryan Parkoff | last post by:
C++ programmers and I tried to experience by writing 65536 switch cases. It is too large for Windows XP and other operating system to handle. It looks like that JMP Table obtains 256K bytes for...
15
by: Stormkid | last post by:
Hey Gang, I'm trying to figure out the best way to add two times together of the format hh:mm:ss any suggestions would be great thanks Todd
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
47
by: Pierre Barbier de Reuille | last post by:
Please, note that I am entirely open for every points on this proposal (which I do not dare yet to call PEP). Abstract ======== This proposal suggests to add symbols into Python. Symbols...
1
by: Steven Brown | last post by:
Hello, the documentation for string marshalling says that the runtime will free the memory of strings returned by unmanaged functions, like in: extern string foo(); The TestStringAsResult...
2
by: leo2100 | last post by:
Hi, I need help with this program. The program is supposed to take a text file and identify the words in it, then it should print them and count how many times a word is repeated. At first main...
0
by: steve.lorimer | last post by:
Thank you for taking the time to look at this: I'm looking for a pre-processor command that will allow me to resolve const strings into const char literals at compile time. Looking at the code...
14
by: =?Utf-8?B?QmVu?= | last post by:
Hi all, I'm trying to understand the concept of returning functions from the enclosing functions. This idea is new to me and I don't understand when and why I would need to use it. Can someone...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.