Professional Documents
Culture Documents
Assignment 3 - Soll
Assignment 3 - Soll
BS Data Science
Computer Programming (CS103) (Fall 2021)
Marks (20)
Assignment #03 (Sol) Semester 1st Submission Date: 20th -Dec-2021
#include <iostream>
using namespace std;
int main()
{
cout<< ”your registration number”;
\\ Your code for problem set program.
return 0;
}
Problem set 1: [10]
Write a function in C++ that rolls a pair of dice until the sum of the numbers rolled is a specific
number. We also want to know the number of times the dice are rolled to get the desired sum.
Note that: The smallest number on each die is 1, and the largest number is 6. So the smallest
sum of the numbers rolled is 2, and the largest sum of the numbers rolled is 12. Use the random
number generation approach to randomly generate a number between 1 and 6.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int num, rollDice(int num);
int main()
{
cout << "Enter the number you want the two dice to
equal:"<<endl;
cin >> num;
while(num>12 || num<2)
{
cout<<endl<<"Please Enter valid number between 2 &
12"<<endl;
cin>>num;
}
cout<<endl<<"The number of times the dice are rolled to get
the sum"<< num << " = " <<
rollDice(num)<< endl;
return 0;
}
GHULAM ISHAQ KHAN INSTITUTE OF ENGINEERING SCIENCES AND TECHNOLOGY
BS Data Science
Computer Programming (CS103) (Fall 2021)
Marks (20)
Assignment #03 (Sol) Semester 1st Submission Date: 20th -Dec-2021
do
{
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
sum = die1 + die2;
rollCount++;
}
while (sum != num);
return rollCount;
}
Output:
Marks (20)
Assignment #03 (Sol) Semester 1st Submission Date: 20th -Dec-2021
Marks (20)
Assignment #03 (Sol) Semester 1st Submission Date: 20th -Dec-2021