PDA

Click to See Complete Forum and Search --> : A Little Help!?!?


FunyBunyFartAHH
Jan 7th, 2003, 08:47 PM
Hey people, I need some help, I got a new book, and it tells right off the bat to do this to write out all the ASCII characters:


#include <iostream>

main <void>
{
unsigned char ASCIIValue = 0;

while (ASCIIValue < 256)

std::cout.put (ASCIIValue);
ASCIIValue ++;


return 0;
}



Ok so why the hell dose it not work, this book is using VC++, and im using the same complier, so could osme one plz tell me ***?

Gives errors do to ";" not being behind < or something.

kedaman
Jan 7th, 2003, 11:40 PM
int main(void)
instead of
main <void>

transcendental
Jan 7th, 2003, 11:44 PM
#include <iostream>

int main (void)
{
unsigned char ASCIIValue = 0;

while (ASCIIValue <= 255)
{
std::cout.put (ASCIIValue);
ASCIIValue ++;
}

return 0;
}



You forgot to put curly brackets for the while loop

Edited: the upper limit of unsigned char is 255

CornedBee
Jan 8th, 2003, 03:50 AM
If what you first posted is what your book told you to do then throw it away.

parksie
Jan 8th, 2003, 05:46 AM
Or send it to me so I can televise its ritual destruction, followed by posting the pieces to the publisher.

:)

CornedBee
Jan 8th, 2003, 09:42 AM
How about ritually destructing the author?

FunyBunyFartAHH
Jan 8th, 2003, 01:53 PM
lol yeah it was a type from the book..

FunyBunyFartAHH
Jan 8th, 2003, 01:54 PM
bah I meant typo

CornedBee
Jan 8th, 2003, 03:16 PM
Bad enough that a c++ book gives main no return type. That's a very bad manner that shouldn't even be started.

FunyBunyFartAHH
Jan 8th, 2003, 05:31 PM
I know what you mean, it should have been left main ().

Jop
Jan 8th, 2003, 06:40 PM
No he means the return type, like
int Main (...) I guess.

FunyBunyFartAHH
Jan 8th, 2003, 09:52 PM
I know I meant the return type, thats why I said leave it empty instead of putting void main ( ) main (void)

parksie
Jan 9th, 2003, 04:26 AM
Leave what empty?

The definition is:int main(int argc, char **argv);You can miss off argv, or argc AND argv. Since we're talking about C++, a blank argument list () is acceptable. In C, if main did not require arguments, it should be given as:int main(void);because in C, a blank argument list means it can take any number, rather than taking none, as in C++.

kedaman
Jan 9th, 2003, 04:44 AM
it could still have been a typo, because there's return 0;
what does the other examples in the book have?

CornedBee
Jan 9th, 2003, 05:11 AM
Don't they ever take a look at their books?