goto usage
Quick program run down -> enter numbers, porgram does the math, porgram asks user if they would like to do it again.
However it doesn't work. I think I'm using goto wrong but have not found much of anything thats helpfull. Code:
|
Why don't you put the stuff that gets called over and over in a seperate function, have that function return a char (the response to "would you like to continue"). And then have your main loop do something like this:
repeat = loop(); while((repeat == 'y') || (repeat == 'Y")) { repeat=loop(); } goto's are consider by most to be terrible programming form in C/C++. |
In case I didn't make myself clear... this works:
Code:
#include <iostream> |
thanks jtshaw.,
P.S. I use the GCC compiler but never have any problems using #include<iostream.h> but thanks for the tip. |
Ya, with newer versions of gcc and the -Wall option you might get a message like this:
warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated. That is why I knocked off the .h. The new way of doing C++ you don't put the extension. math.h is a C header which is why you keep the .h there. |
syntax of goto:
{ /* some code */ loop: /* some more code */ goto loop: } |
All times are GMT -5. The time now is 03:11 PM. |