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])'
DUB1799
0
Newbie Poster
Recommended Answers
Jump to Post
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 …
Jump to PostOnly 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 = …
All 8 Replies
vmanes
1,165
Posting Virtuoso
kortneycoles
0
Newbie Poster
DUB1799
0
Newbie Poster
nullptr
167
Occasional Poster
DUB1799
0
Newbie Poster
vmanes
1,165
Posting Virtuoso
DUB1799
0
Newbie Poster
vmanes
1,165
Posting Virtuoso
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.