Hello,
I'm trying to write a program that will allow the user to choose the sum of the dice and also the number of times the dice can be rolled. Here is the program

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>


using namespace std;

int rollDice(int num);



int Main()


    {


    cout << "The desired sum to be rolled " << endl;
    cin >> "Enter number"; cout << endl;

    cout << "The number of times the dice are rolled to "
         << "get the sum of the dice = " << endl;
    cin >> "Enter number "; cout << endl;

         return 0;
}

int rollDice (int num)
{
    int die1;
    int die2;
    int sum;
    int rollCount = 0;

    srand((unsigned int)time(0));
    do
    {
        die1 = rand() % 6 + 1;
        die2 = rand() % 6 + 1;
        sum = die1 + die2;
        rollCount++;
    }
    while (sum != num);

    return rollCount;

}



But I keep getting this error:

while trying to match the argument list '(std::istream, const char [14])'

cin >> "Enter number";
You cannot do input to a literal string. You need a variable as the right hand side of the extraction operator (>>), like:

int num;
cin >> num;

int rolls;
cin >> rolls;

You don't necessarily need to follow an input statement with an output to make a new line - that will happen when the user enters some value. Only do that when you want to have a blank line between the input and the next output.

Only a small change is needed.

   int x, y;
     cout << "The desired sum to be rolled: " << endl;
    cin >> x; cout << endl;
    cout << "The number of times the dice are rolled to "
    << "get the sum of the dice = " << endl;
    cin >> y; cout << endl;
I tried the change suggested and received the following error:

1>------ Build started: Project: Win32Project1, Configuration: Debug Win32 ------
1>  Source.cpp
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\users\james\documents\visual studio 2012\Projects\Win32Project1\Debug\Win32Project1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


This is how I wrote the program:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int rollDice(int num);
int Main()


        {


    int x, y;
     cout << "The desired sum to be rolled: " << endl;
    cin >> x; cout << endl;
    cout << "The number of times the dice are rolled to "
    << "get the sum of the dice = " << endl;
    cin >> y; cout << endl;
         return 0;
}
int rollDice (int num)
{
    int die1;
    int die2;
    int sum;
    int rollCount = 0;
    srand((unsigned int)time(0));
    do
    {
        die1 = rand() % 6 + 1;
        die2 = rand() % 6 + 1;
        sum = die1 + die2;
        rollCount++;
    }
    while (sum != num);
    return rollCount;
}

line 18: int Main() should be int main() - note case sensitivity.
Also you never call your rollDice function, so you'll never know the roll count.
line 29: does nothing, seeing as you are not getting input for y from the console.

Can you work out how and where to call your rollDice function?

That may be part of the problem. I'm basically new to C++. It has been a long time since I have done anything like this.

Another part of the problem is that you probably set up your project in Visual Studio as a Win32 app, not a console app. You need to pay close attention as you go through the setup steps.

It is in the console app and I still get the error: 1> Source.cpp
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\users\james\documents\visual studio 2012\Projects\Win32Project1\Debug\Win32Project1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I would suggest you start a new project, being careful in the project type. Copy your current code file to that new project folder and add the file to the project sources.

Check this project setup tutorial, page 3 and 4.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.