If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Do {} while errors

Hey all,
Started learning C++ a few days ago, and just finished my first half-useful program. It's basically a converter for weight, distance and currency.
My question is, is there any better way to do this? Any general tips?
And for some reason, when I did the do { code } while, I got an error code about the compiler not recognising the system and return commands. Then, suddenly, it worked. Why?

Re: Do {} while errors

I'd do the whole thing with arrays and get rid of the big case statement. Set up arrays that store the input and output unit names and the multiplier values and then you can replace the entire case statement with just one cin and one cout statement - two lines of code.

Re: Do {} while errors

Hey all,
Started learning C++ a few days ago, and just finished my first half-useful program. It's basically a converter for weight, distance and currency.

So I'll ask you --

what if there were 100 conversions available? Would you write a case statement that has 100 sections, or a gigantic while loop condition with 100 tests? What if that number were upped to 300 different conversions? You would quit C++ as fast as anything if you really had to write 300 case statements and one heck of a gigantic while loop condition at the end.

This is a time to take a step back, look at your code, and determine if this is the way to write something like this. As GCDEF stated, learn to use arrays

Re: Do {} while errors

To add to what GCDEF said, if you store the unit names and multipliers in an array it is then easy to modify the program to store the conversion data externally, rather than hard-coded within the source code. That is, you store the names and multipliers in a text file which is read in and stored in arrays when the program starts. This would allow the user to add/remove items, or modify the multipliers (in the case of the currency exchange rates) without having to modify the program.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.