The program runs but what I want to know is if I did things that were unnecessary? or was there an easier way to write it? this was what I had to do:
Write a program that displays a menu allowing the user to select one of these four gases (Gases are listed in the program). After a selection has been made, the user should enter the number of seconds it took for the sound to travel in this medium from its source to the receiver where it was detected. The program should then report how far away (in meters) the source of the sound was from the detected location.
Input validation:
Check that the user has entered one of the available menu choices.
Do not accept times less than 0 seconds or more than 30 seconds.
Hello Newie. Overall, your code is pretty nice. I find it funny seeing someone use do-while loops, but if it works, it works. As for any corrections in the more proper sense, line 30 is a bit weird. The line is the while loop check, and what you have is: } while (displayMenu);
But the thing is, you mine as well have while(true) instead. Why? It isn't actually calling the function displayMenu, for your code would look like while (displayMenu()), having the brackets, but instead it is simple going "does displayMenu exist?", but it does (obviously), so every time it goes through, it always says true. Another thing, thou again not really important, is the value of some functions that only get called once, namely computeDistance and displayResults. computeDistance is kinda a complex series of calls just to have the line gasSpeed * gasTime, which would have been simpler just having at line 24. displayResults also isn't too use full since you could just have line 134 at line 28 instead. Lastly, the program doesn't have a clean exit. You get stuck in an infinite loop and never really give the user a chance to leave the program except through closing the window. You might want to add another option in the "Please select a gas" to leave the program. Thanks, Spike :D
Thanks for your time and advice. Also, originally the program I wrote was this (listed below) which is called 'mission 5' and is based on mission 3 & 4. The funny thing is that I never wrote 3 & 4 so I went straight to 5. After writing mission 5 I started to remove certain things to make it seem as mission 3 hahah. I just wasn't sure about things because I didn't want to have anything in there that wasn't necessary as it would have resulted in points off.
Sorry for the delayed response. Simple answer, you just need to write while(true);. Long answer, while loops, if statements and the middle part of for loops for(not here;here;not here either)
use statements to see if the condition is met to continue using it. A statement can be true or false. You can use a comparison to get the true or false (ie, X == 5), but you can also just simple type the answer (ie, just but if(true), then it will always be true). More into it, false only is false if the statement equals 0, while true is true if the statement does not equal 0 (apposed to equaling 1). Here is some examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// assume iostream with namespace std
int x = 10;
if (x < 11)
cout << "This would display, for the statement is true\n";
if (x > 5 && x != 10)
cout << "This won't display, for the statement is false\n";
if (true)
cout << "This will display, for true == 1\n";
if (false)
cout << "This won't display, for false == 0\n";
if (7)
cout << "This will display, for anything but 0 is true\n";
if (((x/2)-5))
cout << "This will not display for the answer will be 0, which is false\n";
Hope this helps a bit. I'm not the best at explaining things.