Author Topic: Need C++ Help  (Read 3144 times)

January 28, 2004, 03:50:28 PM
Read 3144 times

Isamil

  • Onos

  • Offline
  • ***

  • 597
    • View Profile
    • http://
I'l update this whenever I change the code.
Code: [Select]
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
  int score;
  score = 0;
  string help;
  string thehelp;
  string one;
  string two;
  string three;
  string four;
  string five;
  thehelp = "You will be given questions about Social Studies.  When you get the question,   you get 3 choices.  You will then press A, B, or C and hit enter. You move onto the next question, and if you got the last question right, you will get a point.";
  cout<<"Welcome to the Social Studies game"<<endl;
  cout<<"If you want to learn how to play, press A.  If you want to play, press B"<<endl;
  cin>>help;
  if(help == "A") {
    cout << thehelp <<endl;
  }
  else( help == "B") {
    cout<<"First question"<<endl;
    cout<<"Who were carpetbaggers?"<<endl;
    cout<<"\tA:People who made carpet"<<endl;
    cout<<"\tB:People who went into the south looking to become rich"<<endl;
    cout<<"\tC:A type of bird"<<endl;
    cin>>one;
    }
    if (one == "B") {
        score++;
        }
    else() {
    
  }
  
  system("PAUSE");
  return 0;
}

What is wrong with my code?

January 28, 2004, 03:55:31 PM
Reply #1

Sancho

  • Legacy Admin
  • Fade

  • Offline
  • **

  • 473
    • View Profile
    • http://
Try this:

Code: [Select]

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
 int score;
 score = 0;
 string help;
 string thehelp;
 string one;
 string two;
 string three;
 string four;
 string five;
 thehelp = "You will be given questions about Social Studies.  When you get the question,   you get 3 choices.  You will then press A, B, or C and hit enter. You move onto the next question, and if you got the last question right, you will get a point.";
 cout<<"Welcome to the Social Studies game"<<endl;
 cout<<"If you want to learn how to play, press A.  If you want to play, press B"<<endl;
 cin>>help;
 if(help == "A") {
   cout << thehelp <<endl;
 }
 else if( help == "B") {
   cout<<"First question"<<endl;
   cout<<"Who were carpetbaggers?"<<endl;
   cout<<"\tA:People who made carpet"<<endl;
   cout<<"\tB:People who went into the south looking to become rich"<<endl;
   cout<<"\tC:A type of bird"<<endl;
   cin>>one;
   if (one == "B") {
       score++;
   }
 }
 
 system("PAUSE");
 return 0;
}

Disclaimer:  I don't really know C++, so I'm just guesstimating.
« Last Edit: January 28, 2004, 04:06:14 PM by Sancho »

January 28, 2004, 04:01:37 PM
Reply #2

Isamil

  • Onos

  • Offline
  • ***

  • 597
    • View Profile
    • http://
Did that:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing  make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include/c++"  -I"C:/Dev-Cpp/include/c++/mingw32"  -I"C:/Dev-Cpp/include/c++/backward"  -I"C:/Dev-Cpp/include"  

main.cpp: In function `int main(int, char**)':

main.cpp:24: parse error before `{' token

main.cpp: At global scope:
main.cpp:36: ISO C++ forbids declaration of `system' with no type
main.cpp:36: `int system' redeclared as different kind of symbol
C:/Dev-Cpp/include/stdlib.h:373: previous declaration of `int system(const
   char*)'
main.cpp:36: invalid conversion from `const char*' to `int'
main.cpp:37: parse error before `return'

make.exe: *** [main.o] Error 1

Execution terminated

January 28, 2004, 04:17:29 PM
Reply #3

Isamil

  • Onos

  • Offline
  • ***

  • 597
    • View Profile
    • http://
Ok it works now, I'l post again if something else comes up.