Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-30-2008, 02:02 PM
ozyabm ozyabm is offline
Newbie
 
Join Date: Jun 2008
Posts: 1
Credits: 0
Rep Power: 0
ozyabm is on a distinguished road
Lightbulb Switch statement in string returning method...

Hi,

Here is a method inside a string returning function:

Code:
string computeSin(argument 1, argument 2)
{

if ( strcmp(icmop->icmo_addl_infop->retval_str, "USA") == 0 )
	    {         
	      string newIsin = (string)"US" + icmop->icmo_tranche_cusips[trancheNum]; 
	      int d1, d2, sum, multiply, i;
	      
	      for (sum = 0, multiply = 1, i = 10; i > -1; --i) {
		switch (i) {
		case 0:
		case 1:
		  if (isupper(newIsin[i]))
		    d1 = newIsin[i] - 'A' + 10;
		  else
		    return 0;
		  break;
		default:
		  if (isupper(newIsin[i]))
		    d1 = newIsin[i] - 'A' + 10;
		  else if (isdigit(newIsin[i]))
		    d1 = newIsin[i] - '0';
		  else
		    return 0;
		  break;
		}
		
		if (d1 < 10) {
		  d1 *= (multiply ? 2 : 1);
		  multiply = !multiply;
		} else {
		  d2 = d1 / 10;
		  d1 %= 10;
		  d1 *= (multiply ? 2 : 1);
		  d2 *= (multiply ? 1 : 2);
		  sum += (d2 % 10) + (d2 / 10);
		}
		sum += (d1 % 10) + (d1 / 10);
	      }
	      
	      sum %= 10;
	      sum = 10 - sum;
	      sum %= 10;
	      
	      std::stringstream isinSs;
	      isinSs << newIsin << sum;
	      const std::string &checkedIsin = isinSs.str();
	      
	      return checkedIsin;  
	    }
   return argument 2;
}//end of string method
My Question:
If in the switch statement section of this code I reach return 0 (appears twice: once in case 1 and other in default), would I be taken out of this computeSin method or would I keep looping till the for loop finishes?

Normally, a return statement takes you out of a function but in this case if I reach return 0 which is in a switch statement that will keep running till the for loop ends, would I exit the whole method?

Thanks.

Last edited by ozyabm; 06-30-2008 at 02:06 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-30-2008, 04:43 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,385
Last Blog:
wxWidgets is NOT code ...
Credits: 662
Rep Power: 27
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: Switch statement in string returning method...

I believe Return 0 will exit the function completely.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-30-2008, 06:28 PM
dargueta dargueta is offline
Guru
 
Join Date: Oct 2007
Age: 18
Posts: 597
Last Blog:
Programs Under the Hoo...
Credits: 177
Rep Power: 10
dargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the rough
Default Re: Switch statement in string returning method...

Yes, it will. If you want to continue looping, use the continue statement.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-06-2008, 02:50 AM
nutario's Avatar   
nutario nutario is offline
Newbie
 
Join Date: Mar 2008
Location: Germany
Posts: 23
Credits: 0
Rep Power: 3
nutario is on a distinguished road
Send a message via ICQ to nutario Send a message via Skype™ to nutario
Default Re: Switch statement in string returning method...

If qou don't want to use "return 0;", than you can throw a exception instead.
This exception can be caught at the calling point of the function in your programm.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
return, string function, switch



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SecurityAudit vinay Visual Basic Programming 27 01-07-2008 12:14 PM
displaying mysql data into jtextfield.Pls help iz.ziffa Java Help 1 05-31-2007 10:58 AM


All times are GMT -5. The time now is 12:26 AM.

Contest Stats

Xav ........ 1024.41
MeTh0Dz|Reb0rn ........ 974.08
morefood2001 ........ 850.04
John ........ 841.93
WingedPanther ........ 661.52
marwex89 ........ 575.59
Brandon W ........ 447.33
chili5 ........ 292.12
orjan ........ 187.41
Steve.L ........ 181.88

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 79%

Ads