Game Making Help Part 2

closed account (EAUX92yv)
I have progressed on my game. Part 1 of my forum post has been solved. But I've run into another unknown error.

#include "stdafx.h"
#include "iostream"
#include "windows.h"
#include "targetver.h"
#include "string"
using namespace std;
int health=15;
int mana=15;
int inventory;
int partylimit=2;
int jobnum;
string job;
string party1;
string party2;
string jobpartymember;
char q1;
char q2;
char q2b;
char q3;
char q4;
char q4b;
char q4c;
char q4ca;
char q4d;
char q4e;
char q4f;
char q5;
char q6;
char q7;
char q8;
char q9;
char q10;
char q11;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Welcome to World Explorers!\n";
cout<<"In this game, you are a young explorer that wants to have more of an adventurous life\n";
cout<<"In your small village, what job do you have?\n";
cout<<"A. Farmer\n";
cout<<"B. Blacksmith\n";
cout<<"C. Tailor\n";
cout<<"D. Mage\n";
cin>>q1;
if (q1="a" || "A" || "a." || "A.")
{
job="Farmer";
jobnum=1;
}
else if (q1="b" || "B" || "b." "B.")
{
job="Blacksmith";
jobnum=2;
}
else if (q1="c" || "C" || "c." || "C.")
{
job="tailor";
jobnum=3;
}
else if (q1="d" || "D" || "d." || "D.")
{
job="None";
jobnum=4;
}
else
{
cout<<"That is not a valid answer. Please try again.\n";
exit(1);
}
cout<<"Good choice of a job.\n";
Sleep(2000);
system("CLS");
cout<<"One night, you decide that it's time to leave. So, you grab a knife and go.\n";
cout<<"You also take a loaf of bread and knapsack to carry it all in.\n";
if (jobnum=1)
{
jobpartymember="Pablo";
}
else if (jobnum=2)
{
jobpartymember="Mark";
}
else if (jobnum=3)
{
jobpartymember="Joe";
}
else if (jobnum=4)
{
jobpartymember="Bo";
}
cout<<"As you leave your village, you are approached by a man carrying some sort of weapon.\n";
cout<<"\"Who are you?\" you ask.\n";
Sleep(3000);
system("CLS");
cout<<"\"My name is ";
cout<<jobpartymember;"\"";
cout<<"What do you do in respnse to the man approaching you?\n";
cout<<"A. Attack him with your knife\n";
cout<<"B. Continue questioning him\n";
cout<<"C. Run back to your village\n";
cout<<"D. Cast a spell to help escape\n";
cin>>q2;
if (q2="a" || "A" || "a." || "A.")
{
cout<<"You quickly whip out your knife and charge at\n";jobpartymember;".";
cout<<"Unfortunately, your opponent bests you and stabs you in the back. You lay crippled on the ground as you die slowly...\n";
exit(1);
}
else if (q2="b" || "B" || "b." || "B.")
{
cout<<"\"What are you doing here?\"\n";
cout<<"\"I am here to find you. Do you know your own history? It's not even a question to most.\" he responds.\n";
cout<<"At that moment, he attacks you with a shortsword. What do you do in response?\n";
cout<<"A. Dodge the blow and run back to the village\n";
cout<<"B. Block with your knife\n";
cout<<"C. Use magic to bring up a shield\n";
cout<<"D. Shoot a fireball in retaliation\n";
cin>>q2b;
cout<<jobpartymember;"quickly revealed that he was faking out and stabs you in the stomach.\n";
cout<<"You slowly die from blood loss. Your family later finds you when it's too late, and holds a funeral in your honor.\n";
exit(1);
}
else if (q2="c" || "C" || "c." || "C.")
{
cout<<"You run in the direction of your village. You dash into your house and dive into bed.|n";
Sleep(3000);
system("CLS");
cout<<"You wake up in the morning and see that no one else is home. You grab your things and go out again.\n";
}
else if (q2="d" || "D" || "d." || "D.")
{
cout<<"You teleport to your home and go to bed.\n";
Sleep(3000);
system("CLS");
cout<<"You wake up in the morning and see that no one else is home. You grab your things and go out again.\n";
}
cout<<"You walk out to a valley and see a pack of wolves terrorizing a group of innocent citizens. Do you help them?\n";
cout<<"A. Yes\n";
cout<<"B. No\n";
cin>>q3;
if (q3="a" || "A" || " " || "A.")
{
cout<<"You run over to the pack of woles and shoot a fireball in thier direction.\n";
cout<<"You grab your knife and slay the wolves quickly.\n";
Sleep(3000);
system("CLS");
cout<<"\"Thank you for saving us!\" the group says to you.\n";
cout<<"\"Your welcome! Now go, get to safety!\" you tell them.\n";
}
else if (q3="b" || "B" || "b." || "B.")
{
cout<<"You leave the people to their own problems.\n";
Sleep(3000);
system("CLS");
}
cout<<"Afterwards, you find a trail that appears to lead somewhere. Do you follow it?\n";//Remember to make else if and else!!!!!!!!
cout<<"A. Yes\n";
cout<<"B. No\n";
cin>>q4;
if (q4="a" || "A" || "a." || "A.")
{
cout<<"You follow the trail uneventfully for a while before you come across a crossroads.\n";
cout<<"Which way do you wish to go?\n";
cout<<"A. Straight\n";
cout<<"B. Left\n";
cout<<"C. Right\n";
cin>>q4b;
if (q4b="a" || "A" || "a." || "A.")
{
cout<<"You decide to continue going straight.\n";
system("CLS");
cout<<"All of a sudden, a bandit pops out from the side of the road.\n";
cout<<"What do you do in response?\n";
cout<<"A. Dodge his attack and stab him in the back\n";
cout<<"B. Block his attack with your knife\n";
cout<<"C. Cast a spell to block the attack\n";
cout<<"D. Shoot a spell at him in retaliation\n";
cin>>q4c;
if (q4c="a" || "A" || "a." || "A.")
{
cout<<"You feel your knife stab into his back and scrape his spine.\n";
cout<<"You continue on the road.\n";
Sleep(3000);
system("CLS");
}
else if (q4c="b" || "B" || "b." || "B.")
{
cout<<"You block, but he is much stronger and whips the knife out of your hand.\n";
cout<<"You are able to feel his sword stab into you as you die slowly...\n";
Sleep(3000);
exit(1);
}
else if (q4c="c" || "C" || "c." || "C.")
{
cout<<"A hasty ward holds off the inital impact. But you can tell you must do more.\n";
cout<<"What do you do?\n";
cout<<"A. Cast more wards to wear him down\n";
cout<<"B. Attack him with your knife\n";
cout<<"C. Shoot offensive magic at him\n";
cout<<"D. Run away!!!!!!!!!!!!!!!!!!!!\n";
cin>>q4ca;
if (q4ca="a" || "A" || "a." || "A.")
{
cout<<"You quickly put together some more wards to fend off your opponent.\n";
cout<<"This holds him off longer, but in the end, you die.\n";
exit(1);
}
else if (q4ca="b" || "B" || "b." || "B.")
{
cout<<"Your knife can block his attacks, but cannot injure him.\n";
cout<<"He pulls out a bow and shoots you directly in the eye.\n";
cout<<"You die...\n";
exit(1);
}
else if (q4ca="c" || "C" || "c." || "C.")
{
cout<<"You shoot a fireball at your opponent.\n";
cout<<"This kills the bandit.\n";
}
else if (q4ca="d" || "D" || "d." "D.")
{
cout<<"You run away!!!!!!\n";
cout<<"He chases you to a corner.\n";
cout<<"You die...\n";
exit(1);
}
}
}
}
return 0;


My compiler just doesn't run the program. It says the end of the file is found before the left brace. Can someone help me?
closed account (3qX21hU5)
Code is really care to read without the "[ code] [ /code]" (take out the spaces) please use them to help organize your code on the forums so its alot easier for others to read.
Well, there is no closing brace in the code you've posted. So I suppose my eyes tell me the same thing that the compiler is telling you.

Well, that's one problem solved. One more while I'm here.


1
2
3
4
5
6
7
8
char q1;

    cin>>q1;
    if (q1="a" || "A" || "a." || "A.")
    {
        job="Farmer";
        jobnum=1;
    }


q1 is a variable which holds a single character.
"a" is a string of characters (because it uses double quotes).

You need to compare q1 with a character constant in single quotes, like this: 'a'

if we change this q1="a" to this q1='a' it's a step in the right direction, but still not right. The = operator is used to assign a value to a variable, so regardless of what the user typed, q1 now contains 'a'. Instead it needs to use the == operator to test for equality.

The strings "a." and "A." are two characters long and it doesn't make sense to compare them with a single character input. So discard them.

And finally, q1 needs to be compared separately with each required value, like this:
if ( q1 == 'a' || q1 == 'A' )


Well, having noticed that, my instinct is that there are likely to be other problems. But this should help a bit...
Last edited on
I see I'm wasting my time here.


All the errors I've so painstakingly explained above were detailed days ago in the earlier thread: http://www.cplusplus.com/forum/beginner/80774/

Please take the time to read and make use of the help which is offered.
closed account (EAUX92yv)
I tried all of what Chervil said to do, but it still gives me the same error. Can someone explain in further detail what I'm doing wrong? Thanks for the current help!
As well as Chervil's really good post - I would add the following:

If you make use of the toupper or tolower function, you can avoid the double test.

Also, you can use a switch statement instead of a load of if else clauses. If you have more than a few lines of code in a case clause, then put that code into a function. This should keep everything nice & tidy.

Finally, please use code tags - the <> button on the right.

Hope all goes well.
closed account (EAUX92yv)
What are touppers, tolowers, double test, and code tags? Sorry, but I am a beginner.
I suggest you read this - a lot of good things in here:

http://www.cplusplus.com/doc/tutorial/


toupper & tolower are functions that convert a char from lower case to upper case or vice versa.

http://www.cplusplus.com/reference/clibrary/cctype/toupper/


double test


At the moment you have if ( q1 == 'a' || q1 == 'A' ) which is a double test - you are testing the value of q1 twice. If you use the toupper function with your variable q1 first you can do this:

1
2
3
4
cin >> q1;

toupper(q1);
if ( q1 == 'A' )


Which is a lot easier.


Code Tags on the right of where you post, there is a bunch of format buttons. The <> button allows you to format your C++ code as code, as opposed to normal text. It makes it much easier to read. So select your code then press the <> button.

HTH


Typo I'm sure.

toupper(q1);

should be:

q1 = toupper(q1);

Although,

1
2
 if ( toupper(q1) == 'A' )
    .... 


would work just as well.
Last edited on
Topic archived. No new replies allowed.