too few arguments to function `std::string player1(std::string, int, int, int, std::s

This is a discussion on too few arguments to function `std::string player1(std::string, int, int, int, std::s within the C++ Programming forums, part of the General Programming Boards category; Hi! I got this code: Code: #include <cstdlib> #include <iostream> using namespace std; string newgame(); void help(); string makeplayers(string n1, ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    188

    too few arguments to function `std::string player1(std::string, int, int, int, std::s

    Hi!

    I got this code:
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    string newgame();
    void help();
    string makeplayers(string n1, int s1, string n2, int s2);
    string player1(string name, int money, int army, int level, string name2, int money2, int army2, int level2);
    string player2(string name, int money, int army, int level, string name2, int money2, int army2, int level2);
    
    int main()
    {
        string choose;
        
        cout << "Hi! Welcome to Conq. Conq is a multiplayer game.\n";
        cout << "[N]ew game - [H]elp - [E]xit | ";
        cin >> choose;
        
        if (choose == "n" || choose == "N") {
                   newgame();
                   }
        if (choose == "h" || choose == "H") {
                   help();
                   cin.get();
                   }
        if (choose == "e" || choose == "E") {
                   }
    }
    
    string newgame()
    {
           // Player 1
           string name;
           int sort;
           
           // Player 2
           string name2;
           int sort2;
           
           // Player 1's name and type
           cout << "\n\nPlayer 1\n";
           cout << "Name: ";
           cin >> name;
           cout << "Type: ";
           cin >> sort;
           cout << "\n\nPlayer 2\nName: ";
           cin >> name2;
           cout << "Type: ";
           cin >> sort2;
           
           makeplayers(name, sort, name2, sort2);
           cin.get();
    }
    
    void help()
    {
         cout << "\n\nThere are 2 different types.\n1. Money\n2. Army\nMoney:If you choose money, you will get more money but less armies.Army:\nIf you choose army, you will get more armies but less money.\n\n";
         cin.get();
    }
    
    string makeplayers(string n1, int s1, string n2, int s2)
    {
           // Player 1 (n1)
           int army;
           int money;
           int level;
           
           // Player 2 (n2)
           int army2;
           int money2;
           int level2;
           
           // Define Player 1's settings
           if (s1 == 1) {
                    money = 400;
                    army = 5;
                    } else {
                           money = 200;
                           army = 10;
                           }
           level = 0;
           
           // Define Player 2's settings
           if (s2 == 1) {
                    money2 = 400;
                    army2 = 5;
                    } else {
                           money2 = 200;
                           army2 = 10;
                           }
           level2 = 0;
           
           // Player 1's turn
           player1(n1, money, army, level);
    }
    
    string player1(string name, int money, int army, int level, string name2, int money2, int army2, int level2)
    {
           string doo;
           string buy;
           int moess;
           
           cout << "\n-------------------\n" << name << "'s turn\nMoney: " << money << "\nArmy: " << army << "\nLevel: " << level << "\n";
           cout << "\nWhat do you want to do?\n[A]ttack - [G]ather money - [B]uy troops | ";
           cin >> doo;
           
           if (doo == "a" || doo == "A") {
                   
                   if (army > army2) {
                            army = army-1;
                            army2 = army2-2;
                            cout << "You've now got " << army << " troop(s)\n";
                            cout << name2 << " now got " << army2 << " troop(s)\n\n";
                            player2(name, money, army, level, name2, money2, army2, level2);
                   } else {
                          army = army-2;
                          army2 = army2-1;
                          cout << "You've now got " << army << " troop(s)\n";
                          cout << name2 << " now got " << army2 << " troop(s)\n\n";
                          player2(name, money, army, level, name2, money2, army2, level2);
                   }
                   
           } 
           
           if (doo == "g" || doo == "G") {
                   
                   money = money + 20;
                   cout << "You've gathered 20 money!\n\n";
                   player2(name, money, army, level, name2, money2, army2, level2);
                   
                  }
           if (doo == "b" || doo == "B") {
                   
                   cout << "1 troop = 40\n5 troops = 200\nHow many do you want to buy? ";
                   cin >> buy;
                   moess = buy*40;
                   
                   if (moess <= money) {
                             
                   cout << "You've bought " << buy << " troop(s)!\n\n";
                   player2(name, money, army, level, name2, money2, army2, level2);
                   
                   } else {
                          
                          cout << "You cannot buy " << buy << " troop(s)!\n\n";
                          player2(name, money, army, level, name2, money2, army2, level2);
                          
                   }
                  }
    }
    
    string player2(string name, int money, int army, int level, string name2, int money2, int army2, int level2)
    {
           string doo;
           string buy;
           int moess;
           
           cout << "\n-------------------\n" << name << "'s turn\nMoney: " << money2 << "\nArmy: " << army2 << "\nLevel: " << level2 << "\n";
           cout << "\nWhat do you want to do?\n[A]ttack - [G]ather money - [B]uy troops | ";
           cin >> doo;
           
           if (doo == "a" || doo == "A") {
                   
                   if (army2 > army) {
                            army = army-1;
                            army2 = army2-2;
                            cout << "You've now got " << army2 << " troop(s)\n";
                            cout << name << " now got " << army << " troop(s)\n\n";
                            player2(name, money, army, level, name2, money2, army2, level2);
                   } else {
                          army = army-2;
                          army2 = army2-1;
                          cout << "You've now got " << army2 << " troop(s)\n";
                          cout << name << " now got " << army << " troop(s)\n\n";
                          player2(name, money, army, level, name2, money2, army2, level2);
                   }
                   
           } 
           
           if (doo == "g" || doo == "G") {
                   
                   money2 = money2 + 20;
                   cout << "You've gathered 20 money!\n\n";
                   player2(name, money, army, level, name2, money2, army2, level2);
                   
                  }
           if (doo == "b" || doo == "B") {
                   
                   cout << "1 troop = 40\n5 troops = 200\nHow many do you want to buy? ";
                   cin >> buy;
                   moess = buy*40;
                   
                   if (moess <= money2) {
                             
                   cout << "You've bought " << buy << " troop(s)!\n\n";
                   player2(name, money, army, level, name2, money2, army2, level2);
                   
                   } else {
                          
                          cout << "You cannot buy " << buy << " troop(s)!\n\n";
                          player2(name, money, army, level, name2, money2, army2, level2);
                          
                   }
                  }
    }
    And i'm getting errors. Why? Test to compile it!

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Make sure the number of arguments in your function prototypes and definitions match. Also, make sure you don't have an extra argument or missing an argument when calling it.

    In your 'makePlayers' function, you call 'player1', but it only contains a few arguments, not all of them.
    Last edited by Sentral; 04-11-2007 at 06:25 AM.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    how can i make this work:
    buy times 40.
    This doesn't:
    buy*40;

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    I'm guessing
    Code:
    buy*=40;
    Kurt

    EDIT: Ok. That was a stupid reply to an inaccurate question.
    Before you can do any calculations on the string buy you have to convert it to a numercal type.
    Last edited by ZuK; 04-11-2007 at 08:03 AM.

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    138 C:\Users\Fredrik\Desktop\Saker\Projekt\C++\Conq\ma in.cpp no match for 'operator*=' in 'buy *= 40'

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Already mentioned that buy is a string. You can't do multiplication on strings.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You need to first convert the string to an int.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    why dont you use object oriented programming approach for games it's so much better than procedural programming--specially for games
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    What am i using then?

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Procedural programming, as Hussain Hani mentioned. That's where you use functions. In object-oriented programming you use classes. Personally I think his suggestion is a good one, but only once you get the hang of functions, because you need to use functions with OOP as well.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. A Simple (?) Problem
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2001, 05:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21