Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

I'M NO GOOD AT C++ AND NEED HELP


  • Please log in to reply

#1
ands122

ands122

    New Member

  • Member
  • Pip
  • 3 posts
:tazz: 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.

Edited by ands122, 11 June 2005 - 05:43 AM.

  • 0

Advertisements


#2
mannoz

mannoz

    New Member

  • Member
  • Pip
  • 4 posts
Hmmm, I can see that you use a variable schoice1 without decliration!!!!!

u have to add the statment "string schoice1;" instead of "string schoice = "";"!!

I guess this will do help!
  • 0

#3
ands122

ands122

    New Member

  • Topic Starter
  • Member
  • Pip
  • 3 posts
I still got the same error when compiling. If anyone could even tell me what the "return" or "#include" things are I would be grateful (i'm sure a lot of people in these forums can do this).
  • 0

#4
MaverickSidewinder

MaverickSidewinder

    Member

  • Member
  • PipPipPip
  • 257 posts
The #include procedure i think is alright.


Are you by any chance having problems with: Antiquated headers?


That is probably the most common error apart from the ";".

But i copy and pasted your code on DeV-C++. I compiled it and these are the errors that its showing me:

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Dev-Cpp\stupidgame.cpp" -o "C:\Dev-Cpp\stupidgame.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31,
from C:\Dev-Cpp\stupidgame.cpp:2:

C:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
C:\Dev-Cpp\stupidgame.cpp: In function `int main(int, char**)':
C:\Dev-Cpp\stupidgame.cpp:7: error: `string' undeclared (first use this function)

C:\Dev-Cpp\stupidgame.cpp:7: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Dev-Cpp\stupidgame.cpp:7: error: expected `;' before "smarket"
C:\Dev-Cpp\stupidgame.cpp:9: error: expected `;' before "sexplore"

C:\Dev-Cpp\stupidgame.cpp:10: error: expected `;' before "schoice"
C:\Dev-Cpp\stupidgame.cpp:17: error: `schoice1' undeclared (first use this function)
C:\Dev-Cpp\stupidgame.cpp:21: error: `smarket' undeclared (first use this function)

C:\Dev-Cpp\stupidgame.cpp:24: error: `sexplore' undeclared (first use this function)
C:\Dev-Cpp\stupidgame.cpp:26: error: expected `;' before "cout"
C:\Dev-Cpp\stupidgame.cpp:33: error: expected `}' at end of input

Execution terminated

Try following the instructions...


:tazz:


- Maverick

Edited by MaverickSidewinder, 14 June 2005 - 04:22 AM.

  • 0

#5
amieln

amieln

    New Member

  • Member
  • Pip
  • 4 posts
Hi

the problem is that you check in the switch command string

When you must check number of integer type

In order to solve you can define

add to your code

enum {Explore=1,GotoMarket=2}

and when you get Explore choice

set Choice var to

int Choice;

Choice=Explore;

or the other enum value

then in the switch statment check Choice

switch must know before runtime what are the posible choices!!!!!
  • 0

#6
ands122

ands122

    New Member

  • Topic Starter
  • Member
  • Pip
  • 3 posts
It ended up that it was the switch command and the compiler. I got Dev C++ and I entered this new code and after a lot of corrections, got the right code:



 #include <iostream>
 #include <string>
 using namespace std;
  int main()
  {
       
       
       
       //go to the market
       string smarket="shop";
       //explore
       string sexplore="explore";
       //restart
       string srestart="sleep";
       for (;;)
       {
       string schoice1= "";
           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 shop, explore, or\n"
                << " sleep? (type in either explore,\n"
                << " shop, or sleep in exact words).\n\n";
            cin >> schoice1;

          if(schoice1==smarket)
          { 
            cout<< "You go to the market.\n\n";
            break;
          }
          if(schoice1==sexplore)
          {
           cout<< "You explore but get attacked\n"
               << "by a bear. Try again!\n\n";
          }
          if (schoice1==srestart)
          {
          cout<< "you go back to sleep\n\n";
          }
        }           
        return 0;
  }



but thanks for your help everyone! ^_^
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP