Re: Code Formatting Help...
A single function to query the status of all the rooms from the user isn't really practical if the status of each room is stored in a separate variable local to main(). Is that way of storing the room status mandatory in the assignment?
You should remove most of your
Code:
using namespace std;
directives. You only need that once in main(), or, if it is meant to affect more than one function, outside of a function body, right after the #includes.
HTH
Please use code tags the next time you post code, and no line numbers.
Ah, and... Welcome to CodeGuru! :)
Re: Code Formatting Help...
You need to learn to use arrays and loops. What would you do if your hotel had 1,000 rooms?
Re: Code Formatting Help...
Whenever you see a linear pattern in the names, the same thing can be done with an index.
MyVar1 = MyVar[1-1]
MyVar2 = MyVar[2-1]
MyVar3 = MyVar[3-1]
...
To do something with each element, do it using a dynamic index.
Code:
#define LoopForward(min,var,max) for(var=min;var<=max;var++)
int x;
LoopForward(0,x,2) {
MyVar[x] = MyFunction(x);
}
Re: Code Formatting Help...
Quote:
Originally Posted by
Dawoodoz
Whenever you see a linear pattern in the names, the same thing can be done with an index.
MyVar1 = MyVar[1-1]
MyVar2 = MyVar[2-1]
MyVar3 = MyVar[3-1]
...
To do something with each element, do it using a dynamic index.
Code:
#define LoopForward(min,var,max) for(var=min;var<=max;var++)
int x;
LoopForward(0,x,2) {
MyVar[x] = MyFunction(x);
}
That's what I said, but why hide the for loop behind a #define? Completely unnecessary and makes thing more confusing for a beginner.