Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this C++ code for lottery, but it handles the situation wrong where the user inputs a negative value. #include using namespace std; unsigned

I have this C++ code for lottery, but it handles the situation wrong where the user inputs a negative value.

#include

using namespace std;

unsigned long int read_input(string question) {

unsigned long int user_input;

while (true) {

cout

cin >> user_input;

if (user_input > 0) {

return user_input;

} else {

cout

}

}

}

unsigned long int factorial(unsigned long int i) {

unsigned long int k = 1;

while (i > 0) {

k *= i;

i -= 1;

}

return k;

}

unsigned long int calculate_probability(unsigned long int n, unsigned long int p) {

if(p == 0) return 1;

return factorial(n) / (factorial(p) * factorial(n - p));

}

int main() {

unsigned long int balls_tot = read_input("Enter the total number of lottery balls: ");

unsigned long int ball_count = read_input("Enter the number of drawn balls: ");

if (ball_count > balls_tot) {

cout

} else {

cout

}

return 0;

}

It should work like this:

image text in transcribed

Model output: Enter the total number of lottery balls: 3 Enter the number of drawn balls: 4 The number of balls must be a positive number

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data And Hadoop Fundamentals Tools And Techniques For Data Driven Success

Authors: Mayank Bhushan

2nd Edition

9355516665, 978-9355516664

More Books

Students also viewed these Databases questions

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago