Advertisement

C++ Workshop - Looping & Switch Statements (Ch. 7)

Started by July 10, 2006 11:33 AM
48 comments, last by Dbproguy 16 years, 9 months ago
The Express edition of Visual C++ doesn't come with the Windows SDK--which includes, among other things, your missing windows.h file. By default, both console and windows programs include this file. For instructions on setting up a working console project, see the first post in this thread.

[edit] Sorry, I missed that an above post asked you to add the #include "windows.h". To download and install the Windows SDK for Visual C++ Express, follow these instructions.

[Edited by - BeanDog on July 15, 2006 9:24:58 AM]
I was wondering, when you asked for the user to input what color they wanted, did you want them to type in the number, or the actual word? Because if it was the number, then how would you have them exit, if there is the letter q? I am asking because, of course, you would not be able to read the letter q, if the variable type that you are using with cin is an interger right?
Advertisement
I am attempting to download the PSDK-x86.exe file from the link provided. After the dl, the installer window pops up and hangs...forever:( Anybody else having this problem? Or am I downloading the wrong file altogether?
It happened to me too - be patient!

From recollection, the file that you downloaded isn't the actual "guts" of what's needed. That's downloaded subsequently from the website. I checked this by opening my network connections and saw what was being downloaded. It downloaded something quite consistently for about 45 minutes (from my memory).
I have downloaded the full installation, which is split up in around 19 cab files. The full installation will not try to download anything from the internet so it didn't give me any problem installing.

The full installation is around 450 MB in size, so that is probably why it takes so long.

Hope this helps.
I left my computer on all night waiting for the download. When I got up this morning a window was up saying the download server was not responding. This was when I tried to download the X86 file. When I try to download the AMD file, it tells me it isn't a valid win32 application...

Even though I'm on an AMD 3500, but I guess I need to be downloading the X86 file instead...???
Advertisement
Quote:
Original post by RinusMaximus
[opinion]
And that you should use constants for every constant value in your code. So
for (int cars = 10; cars < 100; ++cars){  // cars is the NUMBER of cars being used in some algorithm}


will be

for (int cars = 10; cars < MAX_NUMBER_OF_CARS; ++cars){  // cars is the NUMBER of cars being used in some algorithm}
[/opinion]

I'll have to disagree here. If you're only going to use the literal once, then assigning it to a constant identifier is just tedious. Use a comment (remember those? [smile]) in situations like this.
Quote:
Original post by RinusMaximus
I have a question which is not related to this Chapter, but to the ColorMenu exercise, but since this is the most active topic I'll post it here.

When I was working on the ColorMenu exercise I made an enum for colors which I wanted to add to my Menu class. I was wondering where someone would normally put such an enum.

1. Define the enum globally in the header of the class?
enum COLORS {RED, BLUE, GREEN};class Menu{//class definition};


2. Define the enum as a public member of the class?
class Menu{public:   enum COLORS {RED, BLUE, GREEN};//rest of class definition};


Second solution should be thr preferend one, unless COLORS is used to specify the colors that has nothing to do with a Menu.

Quote:
Original post by RinusMaximus
If the second one is the preferred solution is there also a way to make the enum 'static' so I don't need an instance of the class to use the enum?

So I could use:
Menu.RED;

instead of:
Menu menu;menu.RED;

You can't - only variables and methods can be static in a class. To use an enum (or another type) which has been defined in a class, you must use the scope operator ('::'):
Menu::RED


Regards,
OK... so I've got the color menu program working (a lot of fun to play with, BTW!), but I'm not really happy with the way I'm handling user input, and I'd like to know if there's a better way to handle it.

I'm checking to see if there's a fail state in cin to detect if the user selected 'Q' - but what if I want to add another option? Anyway, here's my method, and if you can help me improve it I'd really appreciate it...
int ColorMenu::QueryUserForNewColor(){    int userInput = -1;    cout << "\nPlease select a color to display your menu:";    cin >> userInput;    if(cin.fail())    {        userInput = -1;        menuColor = MENU_COLOR_DEFAULT;    }    else    {        menuColor = userInput;    }    return userInput;}


Thanks!
evan k. stone | recombinant---------------------------------------aspiring game + audio programmersf bay area, ca, usa
There is nothing special about 'Q' that would make cin fail. IIRC, cin will fail on EOF.

Now, streams do have a fail state. The only way to check and see if 'Q' causes a failure when streaming into an int is to test it. In my experience, it just ignores invalid characters.

This topic is closed to new replies.

Advertisement