
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Hello. I need help with a dice roller program in C++. The program compiles and mostly works, but for negative numbers, I want to just print Illegal value entered. But it also prints the rolling and total, which I should only show with positve numbers not negative numbers. How do I stop the function when a negative number is entered and move on to the next function?

Transcribed Image Text:3 #include <iostream>>
0 #include <cstring>
7 #include <ctime>
8 #include <cstdlib>
9
10
11 void GetDice(int &amount, int &sides);
12 void RollDice(int amount, int sides);
13
int main() {
$995992722222~¦¦¯NEZNAN
14
15
10
17
18
19
20
21
20
GetDice(amount, sides);
23 RollDice(amount, sides);
24
28
30
27 void GetDice(int &amount, int &sides) {
31
32
33
34
35
30
}
44
45
std::cout << "++++ Super Awesome Dice Roller ++++\n";
int amount;
int sides;
}
40
47
48 ✓
49
50
31
52
53
54
33
30
57 }
std::cout << "Enter amount and number of sides: ";
std::cin>> amount >> sides;
37
38
39
40
41
42 void RollDice(int amount, int sides){
43
if(amount < 0 || sides < 0){
std::cout << "\nIllegal value entered...";
amount = 0;
sides = 0;
}
return;
std::cout << "\nRolling << amount << "d" <<< sides <<
srand(100);
int sum = 0;
for (int i = 0; i < amount; i++){
int roll std::rand() % sides + 1;
sum +=roll;
std::cout << roll << '\n';
}
std::cout << "Total: << sum << '\n';
..." << '\n';

Transcribed Image Text:3. Sample Run 3: inputs
++++ Super Awesome Dice Roller ++++
Enter amount and number of sides: 4 10
Rolling 4d10...
1
2
10
3
Total: 18
4. Sample Run 4: inputs 3 4
++++ Super Awesome Dice Roller ++++
Enter amount and number of sides: 3 4
Rolling 3d4...
1
2
4
Total: 7
5. Sample Run 5: inputs
++++ Super Awesome Dice Roller ++++
Enter amount and number of sides: 8 6
Rolling ado...
3
moom n N ND
3
2
Total: 32
6. Sample Run 6: inpute -1 4
++++ Super Awesome Dice Roller ++++
Enter amount and number of sides: -14
Illegal value entered...
7. Sample Run 7: inputs 8-2
++++ Super Awesome Dice Roller ++++
Enter amount and number of sides: 8 -2
Illegal value entered...
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 5 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Using C++ Using your own creativity, make a set of function templates that have these features: This function must return a value. A function template with 1 template parameter, T. And, any other parameters you want. A function template with 2 template parameters, T1 and T2. And, any other parameters you want Within main (): Call your template functions and demonstrate how they work. Construct objects and show off your amazing programming skills!arrow_forwardUsing C++ Using your own creativity, make a set of function templates that have these features: This function must return a value. A function template with 1 template parameter, T. And, any other parameters you want. and then another function template but this time with 2 template parameters, T1 and T2. And, any other parameters you want.arrow_forwardPLEASE HELP! I am looking for the code that is specifically for MyprogrammingLab C++ 5.2 Time Project, or a code that uses a void function with only #include<iostream> 5.2: TimeWrite a program that requests the current time and a waiting time as two integers for the number of hours and the number of minutes to wait. The program then outputs what the time will be after the waiting period. Use 24-hour notation for the times. Include a loop that lets the user repeat this calculation for additional input values until the user says she or he wants to end the program. Input Notes:Both the current time and the waiting time are entered in the form HH:MM where HH and MM are integers signifying hours and minutes respectively. In response to the continuation prompts (described below) the user types a y or a Y to signify "continue" with any other character signifying "quit". Output Notes (Prompts and Labels):At the outset the program prints the title "Compute completion time from current…arrow_forward
- Provide full C++ main.cpp, fraction.cpp, fraction.harrow_forwardCan someone help me to fix my user-defined, value-returning expression? Here's the instructions to my C++ Program: Instructions Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. For the input E, your output should look like the following:E is a vowel: 1 When printing the value of a bool, true will be displayed as 1 and false will be displayed as 0. And here's what I have so far: //Declare include-header files#include <iostream> #include <string.h> //Declare namespace statementsusing namespace std; //Define the isVowel userdefined value-returning functionint isVowel(char ch){if ((ch == 'A') || (ch == "E") || (ch == 'I') || (ch == "O") || (ch == "U") || (ch == 'a') || (ch =='e') || (ch == 'i') || (ch == 'o') || (ch == 'u')) {return true;}else{return false;}}} int main() //Define the main function{//Define variableschar character; //Testing the isVowel function.//Prompt the user to input a…arrow_forwardI am learning c++, and I am really confused about the bool command. Please explain to me how the bool command used and when should I use it! thanks.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education