![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2005
Posts: 5
Rep Power: 0
![]() |
I need help with part of a C++ game script
I have no experience with C++. this is my first program i've written. or at least tried to. I keep on getting this error.
Cannot specify -o with -c or -S and multiple compilations. this is my code: #include <stdio.h>
#include <iostream.h>
#include <string.h>
int main(int nNumberofArgs, char* pszArgs[])
{
//go to the market
string smarket="go to the market";
//explore
string sexplore="explore";
string schoice= ""
cout << "You wake up from a sleep that you\n"
<< "can't remember... That's odd...\n"
<< "You find yourself next to a city.\n"
<< "You also see some money next to you.\n"
<< "Do you want to go to the market,\n"
<< "or explore? (type in either explore or go to market in exact words.)\n";
cin >> schoice1;
switch(schoice1)
{
case smarket:
cout << "You walk into the market\n";
break;
case sexplore:
cout << "You explore. But of course,\n"
cout << "as you should've expected,\n"
cout << "you die. You don't know how,\n"
cout << "you just do.";
break;
default:
cout << "You didn't enter a valid command. Idiot.";
}
return 0;
}by the way. I have C++ for dummies and i didn't even get half way through the book. I just want to make a simple game before I do. I don't know anything about the #include things or the return thing at the end. I was just wondering if anyone could help me. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
First you should not use
#include <stdio.h> #include <iostream.h> #include <string.h> Instead use: #include <iostream> #include <string>
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
and: using namespace std;
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
You cannot switch with strings, too many things to name so here:
#include <iostream>
#include <string>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
//go to the market
int schoice;
cout << "You wake up from a sleep that you\n"
<< "can't remember... That's odd...\n"
<< "You find yourself next to a city.\n"
<< "You also see some money next to you.\n"
<< "Do you want to go to the market,\n"
<< "or explore? (type in either 1 to explore or 2 to go to market in exact words.)\n";
cin >> schoice;
switch(schoice)
{
case 2:
cout << "You walk into the market\n";
break;
case 1:
cout << "You explore. But of course,\n"
<< "as you should've expected,\n"
<< "you die. You don't know how,\n"
<< "you just do.";
break;
default:
cout << "You didn't enter a valid command. Idiot.";
}
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jun 2005
Posts: 5
Rep Power: 0
![]() |
I still got the same problem when I tried to compile it...
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Something more elegant like this should work
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
int main(int nNumberofArgs, char* pszArgs[])
{
int schoice = 1;
cout << "You wake up from a sleep that you\n"
<< "can't remember... That's odd...\n"
<< "You find yourself next to a city.\n"
<< "You also see some money next to you.\n"
<< "Do you want to go to the market,\n"
<< "or explore? \n";
while(schoice)
{
cout << "Type in either 1 to explore or 2 to go to market and 0 to exit\n";
cin >> schoice;
switch(schoice)
{
case 2:
cout << "You walk into the market\n\n" << endl;
break;
case 1:
cout << "You explore. But of course,\n"
<< "as you should've expected,\n"
<< "you die. You don't know how,\n"
<< "you just do.\n" << endl;
break;
case 0:
cout << "Exiting\n";
break;
default:
cout << "You didn't enter a valid command.\n" << endl;
break;
}
}
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Since your problem is apparently with the compiler, you should post the compiler you're using, and the OS/platform. Your respondents can make educated guesses, but they're not psychic. There are additional guidelines in the "How to post a question..." thread in the C forum. You should also investigate the options section of your compiler documentation.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers Last edited by DaWei; Jun 11th, 2005 at 10:31 AM. |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jun 2005
Posts: 5
Rep Power: 0
![]() |
I have GNU compiler and Windows XP. I just want to be able to have them type in the command for what they want to do.
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: May 2005
Location: Colorful Colorado
Posts: 25
Rep Power: 0
![]() |
This problem has nothing to do with code. The compiler options you are using are conflicting.
-o specify the output name of the executable -c forces the output to be sourcefilename.o -S forces the output to be sourcefilename.s -c makes object code which is executable code ready for linking -S makes an assembly file from your code
__________________
How to ask questions the smart way |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Jun 2005
Posts: 5
Rep Power: 0
![]() |
I don't know much about compilers. how do I fix it?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|