473,320 Members | 2,109 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,320 software developers and data experts.

case question

Is there a way I can print a case and then print the previous cases along with the current case selection? For example if I do this

case 3:
printf("*[ 3] 3:59 Radar Love\n");
break;

case 4:
printf("*[ 4] 9:03 Riders On The Storm\n");
break;

and the user selects 3, and then 4 the next time i want it to print out
printf("*[ 3] 3:59 Radar Love\n");
printf("*[ 4] 9:03 Riders On The Storm\n");

is there a way i can do that?
Nov 8 '06 #1
5 1378
sicarie
4,677 Expert Mod 4TB
Is there a way I can print a case and then print the previous cases along with the current case selection? For example if I do this

case 3:
printf("*[ 3] 3:59 Radar Love\n");
break;

case 4:
printf("*[ 4] 9:03 Riders On The Storm\n");
break;

and the user selects 3, and then 4 the next time i want it to print out
printf("*[ 3] 3:59 Radar Love\n");
printf("*[ 4] 9:03 Riders On The Storm\n");

is there a way i can do that?
You can make it a function and call it recursively, though you'd probably have to change the test for them in each case if you did that....

Or you could just combine the two - have a general condition to get into "case 3_and_4", and then have an if statement in there that, if it was 4, printed 4, and had no else, so it would print 3 no matter what if it went in, and might print 4 as well.
Nov 8 '06 #2
hmmm ok.
im still a little bit confused what does this mean.. i could make it a function but if i just call it... like in a for loop or somethin wont it still only print the one case that's selected?

You can make it a function and call it recursively, though you'd probably have to change the test for them in each case if you did that....
Nov 8 '06 #3
sicarie
4,677 Expert Mod 4TB
hmmm ok.
im still a little bit confused what does this mean.. i could make it a function but if i just call it... like in a for loop or somethin wont it still only print the one case that's selected?

You can make it a function and call it recursively, though you'd probably have to change the test for them in each case if you did that....
A function is pretty much, a mini-class. It is declared outside your main, but then can be called. It's good for things that you want to use a lot, but only want to code once.

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.  
  3.     // .... code and initializations here...
  4.     celTmp = convertTmp(farTmp);
  5.     // .... the rest of your code here....
  6. }
  7.  
  8. float convertTmp(float farTmp) {
  9.    float celTmp = 0;
  10.    celTmp = farTmp - 32;
  11.    celTmp = celTmp / 1.8;
  12.    return celTmp;
  13. }
  14.  
That's the most simple example I can come up with off the top of my head, just so you get an idea of functions. From there, a recursive function is one that calls itself a certain number of times (very useful with searching algorithms).

The more I think about it, the more I'd go with the second option - recursive functions and algorithms can get very confusing very quickly. I'd just make a general case and stick an if statement in there.
Nov 8 '06 #4
ok. I'll work on my if statement for now :) thanks for your help i might be back with more questions :)
Nov 8 '06 #5
sicarie
4,677 Expert Mod 4TB
ok. I'll work on my if statement for now :) thanks for your help i might be back with more questions :)
Absolutely, or you can PM me if I'm not watching the forum. :)
Nov 8 '06 #6

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

Similar topics

3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By Clause but unable to use it in WHERE CLAUSE. PLS...
7
by: John | last post by:
Why does the System.IO.FileSystemEventArgs (in FileSystemWatcher object) return lower case for the file? i.e. e.FullName will return "c:\testingfilename.xml" instead of the origiiinal...
10
by: Lakshmi Narayanan.R | last post by:
Hi Experts, Using keyword "To" in select case giving error.The following code is got from www.microsrosoft.com itself. What is the wrong with this?. <% Dim Number1 Number1 = 7 ' Initialize...
11
by: Martin | last post by:
In Plauger's THE STANDARD C LIBRARY (1992) there is the source code for fabs.c (p140). /* fabs function */ #include "xmath.h" double (fabs)(double x) { switch (_Dtest(&x)) { /* test for...
16
by: ME | last post by:
In C# the following code generates a compiler error ("A constant value is expected"): public void Test(string value) { switch (value) { case SimpleEnum.One.ToString(): MessageBox.Show("Test...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
1
by: jl2886 | last post by:
First question: I have an assigned ID that is based on the month and year and then the numbered case. For example, If a new policy came in in March of 07 and he was the 67th person who was entered...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
55
by: aarklon | last post by:
Hi, why general integer expressions are not allowed in case labels in switch statements..????
6
by: Derik | last post by:
Okay, I THINK this is a PHP question... I've been mucking with PHP for awhile now, but just recently I've been poking at some ajax stuff, and I ran into something confusing; my Queries were...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.