Simple C++ Won't Work...

This is a discussion on Simple C++ Won't Work... within the C++ Programming forums, part of the General Programming Boards category; Greetings,
I've just started learning C++ today (my friend suggested it) and I've made my first program. Unfortunately, it won't ...

Simple C++ Won't Work...

Greetings,

I've just started learning C++ today (my friend suggested it) and I've made my first program. Unfortunately, it won't even compile... This may be due to the fact that I have a Mac, and that the header file conio.h was missing from my system so I had to download one from the Internet. The compiler I use (Xcode) lists 16 errors; 15 in the file conio.h and 1 in my main file. The code is as follows:

remove the getch()'s and use the standard ways of taking in input... here's how I'd do that:

Code:

#include <iostream>
//those other two are not neededusingnamespace std; //shake this habit eventuallyint main()
{
char key;
cout<<"I'm a simple C++ program\n\n";
cin>>key; //this is a more standard way of taking in a char
cout<<"To quit the program, press [ENTER]\n"; //this didn't do what you thought it did.
cin.get(); //use this to wait for a keypressreturn 0;
}

remove the getch()'s and use the standard ways of taking in input... here's how I'd do that:

Code:

#include <iostream>
//those other two are not neededusingnamespace std; //shake this habit eventuallyint main()
{
char key;
cout<<"I'm a simple C++ program\n\n";
cin>>key; //this is a more standard way of taking in a char
cout<<"To quit the program, press [ENTER]\n"; //this didn't do what you thought it did.
cin.get(); //use this to wait for a keypressreturn 0;
}

just a note the alert() just seems like a waste of code considering you dont need the extra block of code for it to work. The one I rewrote will work exactly the same as yours it just is one block of code instead of two

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

It could just be a random string that he took from text in the tutorial. Just a thought I was just asking him why he used excessive code for a simple program. Oops I forgot to delete that prototype. Oh well it is fixed now anyways.

> message = "This is an initialized array with a maximum capacity of 255 characters
Who said it was 255?
I know of no such restriction unless it's something specific to your broken compiler.

My compiler isn't broken, it merely does not have the conio.h file. I'm not sure if Apple thought that it would be needed, since not many people compile C++ on a Mac (to my knowledge). I had originally wrote that text because I had the string set at a limit of 255 chars. Afterwards, I removed this and forgot to edit the code.

Raigne, thank you for pointing that out. I have been working on the code, and I now have a slightly larger file. Here is an excerpt:

Yes goto's are evil. I would reccomend using do/while loops, or for... I dont reall see the point in goto other than to mess stuff up. Well anyways if you use do/while be very carful not to intterupt your loop. or make it so that after so far in the program you cant go back. I did that and could figure out how to fix it and had to rewrite the entire code. And rewriting 400 lines of code sux.