More help with c++ please

Discuss Programming
Post Reply
Doogee
administrator
administrator
Posts: 261
Joined: Fri Jan 10, 2003 1:40 am

More help with c++ please

Post by Doogee »

Can someone figure out whats wrong, i dont really understand the errors im getting, here have a look at the source and the compilation errors.

Souce :

Code: Select all

dan@dans-computer:~/prog/cpp$ more number1.cpp
/*
 * Dunno yet :s
 */
 
#include <iostream.h>
 
int linux()
{
int ans;
        cout << "You use Linux, thats good, do you want to proceed?\nUse 1 for yes or  anything else for no\n ";
        cin >> ans;
        if(ans == 1)
        {
                game();
        }
        else
        {
                cout << "Bye then :D\n";
                return 0;
        }
}
int win()
{
        cout << "NO!\n";
        return 0;
}
int other()
{
char ans2;
        cout << "This may or may not work try anyway though\nif it doesnt work email me (doogee@punkass.com)\n";
        cout << "Continue? (1 fpr yes or anythin else for no)\n";
        cin >> ans2;
        if(ans2 == 1)
        {
                game();
        }
        else
        {
                cout "Bye then :D\n";
                return 0;
        }
}
                                                                                                      
int game()
{
        cout << "this is where the game will be\n";
        return 0;
}
                                                                                                      
int main()
{
int os;
        cout << "Welcome to my game, i still havnt figured out what the game will be\n";
        cout << "Im just laying the foundations for the game that will be :D\n\n";
        cout << "Anyway, first things first, what OS are you in right now??\n";
        cout << "1 > Winders\n2 > Linux\n 3 > Other\n\n";
        cin >> os;
        switch(os)
        {
                case 1:
                win();
                break;
                case 2:
                linux();
                break;
                case 3:
                other();
        }
        return 0;
}
And the errors:

Code: Select all

dan@dans-computer:~/prog/cpp$ g++ -o mygame number1.cpp
number1.cpp:7: parse error before `1'
number1.cpp:10: syntax error before `<'
number1.cpp:11: syntax error before `>'
number1.cpp: In function `int other()':
number1.cpp:35: implicit declaration of function `int game(...)'
number1.cpp:39: parse error before string constant
number1.cpp: In function `int main()':
number1.cpp:64: `1' cannot be used as a function
dan@dans-computer:~/prog/cpp$

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Apparently you can't use "linux" for a function. I changed your function names and fixed a couple of other small errors so it would compile but you'll still want to work on it:

Code: Select all

/*
 * * Dunno yet :s
 */

#include <iostream.h>

int game()
{
  cout << "this is where the game will be\n";
  return 0;
}


int islinux()
{
  int ans;
  cout << "You use Linux, thats good, do you want to proceed?\nUse 1 for yes or
 anything else for no\n";
  cin >> ans;
  if (ans == 1) {
    game();
  } else {
    cout << "Bye then :D\n";
    return 0;
  }
}

int iswin()
{
  cout << "NO!\n";
  return 0;
}

int other()
{
  char ans2;
  cout << "This may or may not work try anyway though\nif it doesnt work email me (doogee@punkass.com)\n";
  cout << "Continue? (1 fpr yes or anythin else for no)\n";
  cin >> ans2;
  if(ans2 == 1) {
    game();
  } else {
    cout << "Bye then :D\n";
    return 0;
  }
}

int main()
{
  int os;
  cout << "Welcome to my game, i still havnt figured out what the game will be\n";
  cout << "Im just laying the foundations for the game that will be :D\n\n";
  cout << "Anyway, first things first, what OS are you in right now??\n";
  cout << "1 > Winders\n2 > Linux\n3 > Other\n\n";
  cin >> os;
  switch(os) {
    case 1: iswin();
            break;
    case 2: islinux();
            break;
    case 3: other();
  }
  return 0;
}

Doogee
administrator
administrator
Posts: 261
Joined: Fri Jan 10, 2003 1:40 am

Post by Doogee »

weird!

thanks alot void, youve saved the day again hehehe

Post Reply