943,632 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4394
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jun 6th, 2005
0

Re: Completed Code but A LOT of GOTO...Replacement?

I'm working on it....post will be soon....

Scott
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cscotty is offline Offline
12 posts
since Jun 2005
Jun 10th, 2005
0

Re: Completed Code but A LOT of GOTO...Replacement?

Hey Scott,

I ran across this in another forum...maybe this is another approach you can take?

http://www.daniweb.com/code/snippet10.html

It is similar, I believe, to what you are trying to do.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EricaJanine is offline Offline
22 posts
since Jun 2005
Jun 10th, 2005
0

Re: Completed Code but A LOT of GOTO...Replacement?

While many say GOTO is bad I happen to believe its very handy. 20 is quite a lot though. A few goto's is ok - but 20 may be getting too much. Try replacing the with if/else.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bjdea1 is offline Offline
59 posts
since Jun 2005
Aug 19th, 2010
0
Re: Completed Code but A LOT of GOTO...Replacement?
Hey, [edit] lol wow just realized this is over 5 year old thread [/edit]

i was looking for an example of the goto command and came across this post.

firstly the way I interpret the switch is as a neat way to write a long chain of if else ifs. so..

  1. int i;
  2.  
  3. cin>>i;
  4.  
  5. //a chain of if else if
  6.  
  7. if(i==0){
  8. cout<<"i is 0\n";
  9. }else if(i==1){
  10. cout<<"i is 1\n";
  11. }else if(i==2){
  12. cout<<"i is 2\n";
  13. else{
  14. cout<<"i is not 0 1 or 2\n";
  15. }
  16.  
  17. //now as a case
  18.  
  19. switch(i){
  20.  
  21. case(0): cout<<"i is 0\n";
  22. break;
  23. case(1): cout<<"i is 1\n";
  24. break;
  25. case(2): cout<<"i is 1\n";
  26. break;
  27. default: cout<<"i is not 0 1 or 2\n";

in your situation i would say functions are the way to go, and Dave is showing you something you want to strive towards, Abstraction, which is nice.

now functions work a little different and not only for math, math is easy way to show how a function works, but a function needs a couple things to set it up..

here is a great reference for C++ stuff
http://www.cplusplus.com/doc/tutorial/functions/
Last edited by jack2423; Aug 19th, 2010 at 2:12 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jack2423 is offline Offline
1 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: const
Next Thread in C++ Forum Timeline: Urgent help needed..plz someone help...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC