Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 11-26-2006, 12:28 PM   #1 (permalink)
Newb Techie
 
Join Date: Jun 2005
Posts: 35
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   Reply With Quote
Old 11-27-2006, 02:05 PM   #2 (permalink)
Monster Techie
 
Join Date: May 2004
Location: Tucson, AZ, USA
Posts: 1,183
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   Reply With Quote
Old 11-27-2006, 02:12 PM   #3 (permalink)
Super Techie
 
Join Date: Jul 2004
Posts: 375
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   Reply With Quote
Old 11-27-2006, 11:59 PM   #4 (permalink)
Newb Techie
 
Join Date: Jun 2005
Posts: 35
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   Reply With Quote
Old 11-28-2006, 12:18 AM   #5 (permalink)
Monster Techie
 
Join Date: May 2004
Location: Tucson, AZ, USA
Posts: 1,183
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   Reply With Quote
Old 11-28-2006, 01:36 AM   #6 (permalink)
Newb Techie
 
Join Date: Jun 2005
Posts: 35
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   Reply With Quote
Old 11-28-2006, 01:51 AM   #7 (permalink)
Indeed.
 
Greg's Avatar
 
Join Date: Dec 2004
Posts: 1,533
Default

And where it says
Code:
std::cin >> Character Race;
you would want it to say "CharacterType" instead.
__________________
Greg is offline   Reply With Quote
Old 11-28-2006, 02:00 AM   #8 (permalink)
Newb Techie
 
Join Date: Jun 2005
Posts: 35
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   Reply With Quote
Old 11-28-2006, 02:03 AM   #9 (permalink)
Super Techie
 
Join Date: Jul 2006
Posts: 299
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   Reply With Quote
Old 11-28-2006, 02:08 AM   #10 (permalink)
Newb Techie
 
Join Date: Jun 2005
Posts: 35
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   Reply With Quote
Reply

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



All times are GMT -5. The time now is 01:56 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0