Hi, c++ help       Please see my code   The code reads two numbers from a file and creates a dice which must be played a certain amount of times (dertimined by input file).        The code must then output the results of the multiple dice rolls.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Hi, c++ help

 

 

 

Please see my code

 

The code reads two numbers from a file and creates a dice which must be played a certain amount of times (dertimined by input file). 

 

 

 

The code must then output the results of the multiple dice rolls. 

 

 

 

 

 

For line 1

 

**the numbers in brackets are the results of the multiple dice roll while the last number is the sum of the throws for the first die 

 

As you can see for the first line everything adds up correctly as the results of the dice (in brackets) are summed up correctly (last number) 

 

For the second row and all other following rolls, the code adds the rolls of the new dice and the result of the previous sum to get the new sum. 

 

This should not happen, I want the sum of each rows to be displayed on the end of each line  

 

The correct code should be display **please don't output comment 

 

[2] - [4 ]-[5] - 11 //dice rolled 3 times and sum is 11

 

[1] - [1 ]-2 //dice rolled 2 times with sum 2

Vmain() : int
W
C:AUsers\User\Desktop\11\bin\Debug\11.exe
ent
[2]-[4]-[5]-11
[1]-[1]-13
jects Sym
rkspace
Process returned 0 (0x®)
O Sources Press any key to continue.
11
execution
Transcribed Image Text:Vmain() : int W C:AUsers\User\Desktop\11\bin\Debug\11.exe ent [2]-[4]-[5]-11 [1]-[1]-13 jects Sym rkspace Process returned 0 (0x®) O Sources Press any key to continue. 11 execution
13
srand (time (NULL) ) :
14
ifstream input ("two.txt"):
15
ofstream output ("output.txt");
16
int sides;
17
char dash;
18
int sum-03;
19
int num;
20
int roll=03B
%3D
21
int previous-0;
while (input>>num>>dash>>sides) {
22
for (int i-0; i< num ;i++){
(rand () $sides+l):
24
roll =
%3D
26
sum-roll;
sum=
27
|
28
cout<<"["<<roll<<")"<<"-";
29
30
31
32
3A5 07
222 222
Transcribed Image Text:13 srand (time (NULL) ) : 14 ifstream input ("two.txt"): 15 ofstream output ("output.txt"); 16 int sides; 17 char dash; 18 int sum-03; 19 int num; 20 int roll=03B %3D 21 int previous-0; while (input>>num>>dash>>sides) { 22 for (int i-0; i< num ;i++){ (rand () $sides+l): 24 roll = %3D 26 sum-roll; sum= 27 | 28 cout<<"["<<roll<<")"<<"-"; 29 30 31 32 3A5 07 222 222
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
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
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education