PDA

View Full Version : Problem with my code


Boomer-Aus
05-04-2010, 11:05 AM
Well me and my friend are starting to learn C++ and are making a game we have 2 problems


1. its a choice game so if you choose a choice you create a path and it can vary were going to put a raiting (e.g your a coward, hero) and some other stuff but our major problem is we have made the code were the player puts the input in but for example if the player follows C) we want him/her to follow that path and have diffrent choices depending on the choice he/she has previously made so can anyone help me to get a refrence link to a code or tutorial or even on the forum

2. This problem is kind of.......annoying once the player has made a choice a text appears depending on what he/she did but it only stays on screen for 0.7 seconds (to be exact lol) and the program exits so is their any possible help with that?

if anyway can give me a bit of help that would be great i know the first one is kind of hard to get a refrence to a code etc but we have tried and we don't exactly know the name of the code and can't find it via google


Edit:

Here's the code i have only worked on it for about 4 hours total and its my first code so it maybe defective.........

[Code]

// 5.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"{

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main(){




int a;

#include <iostream>
#include <string>
using namespace std;

int main ()

cout << "Get out of your foxhole soldier unless you want to Die get the hell out of there!!!\n";
cout << "1) stay in your foxhole \n";
cout << "2) Run out of your foxhole\n";
cout << "3) follow the LT\n";
cout << "Enter a choice: ";
cin >> a;

switch (a){

case 1:
cout << "A barrage of motars hit around you, you hold your head down you think about your girlfriend back home suddenly you hear the whizz of motars coming a few hitting nearby you repeat to yourself ''I can't die i can't die!!!!''sundenly a motar hit's and your life ends the last thing you think about is maybe i should of followed the LT ";
break;
case 2:
cout << "you run out of your foxhole the lt here's you and yells come over there the next image you see is the LT dead hit by a motar half of him in a foxhole the other half crawling and dies, you see a medic he's asking what your name is you reply ... he replys copearl ... help me get some wounded and get them the hell out of here!";
break;
case 3:
cout << "you follow the LT he asks what is your name coperal you reply ... ok!!!!! coperal ... they are firing motars instead of 88s it seems that the raid on their supply depot has shrivled there defence i need you to spot for me so i can take the motars out just don't get yourself killed!";
break;

default:
cout << "Not a valid entry...";
break;

[Code]

oracleguy
05-04-2010, 03:37 PM
Add a cin.getline call right before the return statement in your main function. That will hold the console window open.

Boomer-Aus
05-05-2010, 06:53 AM
thanks

for some reason my code isn't working anymore and it won't let me compile can anyone spot somthing with the code?

oracleguy
05-05-2010, 06:55 AM
What are the compiler errors?

Boomer-Aus
05-05-2010, 08:11 AM
1>------ Build started: Project: First, Configuration: Debug Win32 ------
1>Compiling...
1>First.cpp
1>c:\documents and settings\charles\my documents\visual studio 2008\projects\first\first\first.cpp(5) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\documents and settings\charles\my documents\visual studio 2008\projects\first\first\first.cpp(55) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\documents and settings\charles\my documents\visual studio 2008\projects\first\first\first.cpp(102) : fatal error C1004: unexpected end-of-file found
1>Build log was saved at "file://c:\Documents and Settings\Charles\My Documents\Visual Studio 2008\Projects\First\First\Debug\BuildLog.htm"
1>First - 2 error(s), 1 warning(s)

BWiz
05-05-2010, 10:18 AM
#include "stdafx.h"{
Get rid of the brace; so you have


#include "stdafx.h"
For you other error, I'm having trouble reading your code. Did you post one entire file or several different files?



#include <iostream>
#include <string>
using namespace std;

int main(){




int a;

#include <iostream>
#include <string>
using namespace std;

int main ()


What's going on here? Is this part of the same source file? Why you are trying to include inside the main function?

Could you please wrap your source code?

Boomer-Aus
05-05-2010, 02:36 PM
1>------ Build started: Project: First, Configuration: Debug Win32 ------
1>Compiling...
1>First.cpp
1>c:\documents and settings\charles\my documents\visual studio 2008\projects\first\first\first.cpp(5) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\documents and settings\charles\my documents\visual studio 2008\projects\first\first\first.cpp(100) : fatal error C1004: unexpected end-of-file found
1>Build log was saved at "file://c:\Documents and Settings\Charles\My Documents\Visual Studio 2008\Projects\First\First\Debug\BuildLog.htm"
1>First - 2 error(s), 0 warning(s)


the codes better i use a refrence diary i basicly put all of my codes in a text format file so i may have used the int main ()

oracleguy
05-05-2010, 03:04 PM
Remove the include directives you have inside your main function. As for that error, that is because at least according to the code you posted earlier, your main function has no closing brace. Or you have an orphaned open brace.

Boomer-Aus
05-06-2010, 09:48 AM
ok thanks for the help