Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 11th, 2005, 9:59 AM   #1
ands122
Newbie
 
Join Date: Jun 2005
Posts: 5
Rep Power: 0 ands122 is on a distinguished road
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.
ands122 is offline   Reply With Quote
Old Jun 11th, 2005, 10:05 AM   #2
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Jun 11th, 2005, 10:07 AM   #3
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Jun 11th, 2005, 10:12 AM   #4
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Jun 11th, 2005, 10:14 AM   #5
ands122
Newbie
 
Join Date: Jun 2005
Posts: 5
Rep Power: 0 ands122 is on a distinguished road
I still got the same problem when I tried to compile it...
ands122 is offline   Reply With Quote
Old Jun 11th, 2005, 10:24 AM   #6
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Jun 11th, 2005, 10:27 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
DaWei is offline   Reply With Quote
Old Jun 11th, 2005, 10:36 AM   #8
ands122
Newbie
 
Join Date: Jun 2005
Posts: 5
Rep Power: 0 ands122 is on a distinguished road
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.
ands122 is offline   Reply With Quote
Old Jun 11th, 2005, 10:42 AM   #9
jubitzu
Newbie
 
Join Date: May 2005
Location: Colorful Colorado
Posts: 25
Rep Power: 0 jubitzu is on a distinguished road
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
jubitzu is offline   Reply With Quote
Old Jun 11th, 2005, 10:46 AM   #10
ands122
Newbie
 
Join Date: Jun 2005
Posts: 5
Rep Power: 0 ands122 is on a distinguished road
I don't know much about compilers. how do I fix it?
ands122 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC