Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 11-26-2006, 12:28 PM   #1 (permalink)
 
Newb Techie

Join Date: Jun 2005

Posts: 35

mrserv0n

Send a message via AIM to mrserv0n
Default Help With C++ Very Basic

Hey I am doing this tutorial for a program for class, I know nothing of C++ so bear with me.

This project is set to create console application.

Here is the code

/* '01 Main.cpp' */
#include <stdafx.h>

main (void)
{
/* Variable declarations*\
unsigned char Age;
long StartEnergy;
char CharacterType;

/* Get the Information *\
std::cout << "What is your Character's Age?: ";
std::cin >> Age;
std::cout << "How much start Energy?: ";
std::cin >> Start Energy;
std::cout << " Character Race?: ";
std::cin >> Character Race;

/*Show the information*\
std::cout << "Your chacter is " << Age << " years old." << std::endl;
std::cout << "Has " << StartEnergy << " of starting energy." << std::endl;
std::cout << "And its race is " << CharacterType << *.* << std::endl;
return 0;
}


Ok now whenever I go to Debug or Run it it just says "filename.exe not found" Well how do I get to preview my little text program? or run it period for that matter.
mrserv0n is offline  
Old 11-27-2006, 02:05 PM   #2 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default

What compiler / program are you using? Sounds like it's not compiling, hence no file (filename.exe) to run?
__________________
Vormund is offline  
Old 11-27-2006, 02:12 PM   #3 (permalink)
 
Super Techie

Join Date: Jul 2004

Posts: 375

Nikkon

Default

I see some syntax errors.
__________________
AMD 3800+ X2
Zalman CNPS7000B CPU Heatsink/Fan
ASUS A8N Premium
2 GB G. Skill DDR 400 (2 X 1 GB)
1 GB Ultra DDR 400 (2 X 512 GB)
eVGA 7800GT 256MB
120 GB seagate HD (7200RPM)
80 GB Seagate HD (7200RPM)
Sound Blaster Audigy 2 Platium ZS Sound Card
Logitec z5300 5.1 THX certified speaker
Medusa 5.1 Headphones
ATI TV turner card
DVD Drive
CD Burner Drive
Razer Copperhead Gaming mouse
Nikkon is offline  
Old 11-27-2006, 11:59 PM   #4 (permalink)
 
Newb Techie

Join Date: Jun 2005

Posts: 35

mrserv0n

Send a message via AIM to mrserv0n
Default

I an using Visual Studio 2005. I am not sure about a compiler. I mean I shouldnt have to compile this just to see it, its just a text dos console. Basically just like the simple Hello world tutorial. Which does run by the way.


As for second poster. Can you be more specific what syntax error do you see? VS doesn't seem to say there are any. And the code is taken straight from a college text book word for word...
mrserv0n is offline  
Old 11-28-2006, 12:18 AM   #5 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default

Don't know why I didn't see this the first time--this is most likely the problem:

Your comments:

/* '01 Main.cpp' */
/* Variable declarations*\
/* Get the Information *\
/*Show the information*\

Open: /*
Close: */

And since after the variable declaration comment, the comment is never closed--well, there's no program there.

So it should be:
Code:
/* '01 Main.cpp' */
#include <stdafx.h>

main (void)
{
/* Variable declarations*\
unsigned char Age;
long StartEnergy;
char CharacterType;

/* Get the Information */
std::cout << "What is your Character's Age?: ";
std::cin >> Age;
std::cout << "How much start Energy?: ";
std::cin >> Start Energy;
std::cout << " Character Race?: ";
std::cin >> Character Race;

/*Show the information */
std::cout << "Your chacter is " << Age << " years old." << std::endl;
std::cout << "Has " << StartEnergy << " of starting energy." << std::endl;
std::cout << "And its race is " << CharacterType << *.* << std::endl;
return 0;
}
I don't have VS to test, right now. >.>

As well, if there are other syntax errors, now VS should tell you.
Vormund is offline  
Old 11-28-2006, 01:36 AM   #6 (permalink)
 
Newb Techie

Join Date: Jun 2005

Posts: 35

mrserv0n

Send a message via AIM to mrserv0n
Default

oh Jeez thank you so much. I can see how that was easy to overlook for even myself. I swear I have stared at it for hours lol. Thank you so much Ill try it.
mrserv0n is offline  
Old 11-28-2006, 01:51 AM   #7 (permalink)
Greg's Avatar
 
Indeed.

Join Date: Dec 2004

Posts: 1,554

Greg is on a distinguished road

Default

And where it says
Code:
std::cin >> Character Race;
you would want it to say "CharacterType" instead.
__________________
Greg is offline  
Old 11-28-2006, 02:00 AM   #8 (permalink)
 
Newb Techie

Join Date: Jun 2005

Posts: 35

mrserv0n

Send a message via AIM to mrserv0n
Default

Thank you yea I found a couple other errors too but got it working.

In my book for school it says #include <stdafx.h>

However I got tan error saying not found. When I switched it to #include <iostream> it worked fine. What is stdafx.h and why does my college book use that?
mrserv0n is offline  
Old 11-28-2006, 02:03 AM   #9 (permalink)
 
Super Techie

Join Date: Jul 2006

Posts: 298

KBlair is on a distinguished road

Default

Stdafx.h is outdated, Visual Studio 2005 uses the newer standard, and that is iostream, which you used.
__________________

See Wii. See Wii run. See Wii blow all the other consoles out of the water!
KBlair is offline  
Old 11-28-2006, 02:08 AM   #10 (permalink)
 
Newb Techie

Join Date: Jun 2005

Posts: 35

mrserv0n

Send a message via AIM to mrserv0n
Default

Ok one last question when I run this program in Visual C++ 6.0 it works fine. I copy the same code to VS 2005 and I get this error

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
mrserv0n is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On