help with code problem

This is a discussion on help with code problem within the C++ Programming forums, part of the General Programming Boards category; When I run this code I get an error saying that the function int DiceNum(int) has too few arguments. Does ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    7

    help with code problem

    When I run this code I get an error saying that the function int DiceNum(int) has too few arguments. Does anyone have any ideas? And also can anyone tell me how to loop the game to restart at the end if the user chooses?

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    
    using namespace std;
    
    int randGen(int x);                 //function for generating random on die
    int DiceNum(int num);               //function for the 6 different dice rolls
    
        short int diNumI;               //dice number bet on
        int moneyO = 0;                 //points record variable
        unsigned int moneyB;            //money places in bet
    
    int main()
    {
        cout << "Place a bet 5, 10, 25, or 100: ";
    
        unsigned short int dNum;            //dice number choice input by the player (variable statement)
    
        cin >> moneyB;
    
        switch(moneyB)
        {
            case 5:
                cout << "What number will the die land on? \n";
                cin >> diNumI;
                cout << "Push Enter to roll die. \n";
                DiceNum();
                break;
    
            case 10:
                cout << "What number will the die land on? \n";
                cin >> diNumI;
                cout << "Push Enter to roll die. \n";
                DiceNum();
                break;
    
        }
    
        return 0;
        cin.get();
    }
    
    
    
    int randGen(int x){          //random generator function
    
        srand(time(0));
        x = 1+(rand()%6);
        cout << 1+(rand()%6);
        return x;
    }
    
    int DiceNum(int num){
    
        char Lchoice[3];        //choice to play again
    
        num = randGen();
    
        if(diNumI == num){      //if die number guess is correct
            cout << "You won! \n";
            moneyO = moneyO + moneyB;
            sleep(1000);
            cout << "Try again?"
            cin >> Lchoice;
                if(Lchoice == 'yes'){
                    //restart
                }
                else if(Lchoice == 'no'){
                return 0;
                }
        }
    
        else if(diNumI !== num){
            cout << "No the number was ";
            cout << num;
            cout << "Try again?\n";
            cin >> Lchoice;
    
                 if(Lchoice == 'yes'){
                    //restart
                    return 1;
                }
                else if(Lchoice == 'no'){
                return 0;
                }
        }
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,743
    Quote Originally Posted by Jayb
    When I run this code I get an error saying that the function int DiceNum(int) has too few arguments. Does anyone have any ideas?
    Yes: when you call DiceNum, provide an argument. That is, this is wrong:
    Code:
    DiceNum();
    Your compiler's error message should have included a line number telling you as such.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    7
    Oh wow I feel stupid. Thanks. It didn't have a marker showing me this line that's why I didn't notice it right away. Do you know how to loop this to where if they choose to play again it loops?

  4. #4
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    @Jayb - even without showing you the line - the compiler told you exactly and word by word what was wrong. Sometimes it's a bit more difficult to make sense out of compiler messages; but still, *reading* them is always the first thing to do. (No offense here, just a hint.)

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Error messages can be difficult to understand for those without experience. Those new to a programming language will almost certainly have trouble interpreting error messages. Then there's the problem of switching between compilers...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Quote Originally Posted by Elysia View Post
    Error messages can be difficult to understand for those without experience. Those new to a programming language will almost certainly have trouble interpreting error messages. Then there's the problem of switching between compilers...
    Sure, no argument here. I spotted that too. Nevertheless, reading the messages is a good thing to do. First of all, as you make your progress, you will gain understanding of those messages bit by bit, and secondly, in this special case, the message told Jayb exactly and without any need for interpretation what the problem was.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code tag problem
    By siavoshkc in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 09-26-2006, 11:42 AM
  2. Code problem
    By dot_rain in forum C Programming
    Replies: 1
    Last Post: 11-21-2003, 03:30 PM
  3. code problem
    By kashifk in forum C Programming
    Replies: 6
    Last Post: 04-22-2003, 05:22 PM
  4. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM

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