1. Find as many errors in the C program: Put the errors in a list. Please help B
ID: 654046 • Letter: 1
Question
1. Find as many errors in the C program: Put the errors in a list. Please help
Below is a short C program, dice.c that simulates rolling
two dice 10000 times and keeps track of how many of each possible
result (2 .. 12) actually arise.
Below that is a table of "tokens" that a "typical" lexor would
return. The table has columns to text (the actual character(s) of
the C program that make up the token, type(a representation of the
type of token that is actually numbered typically using #define),
and a value, which is some that is passed along to the parser
ALONG with the type.
And the "number" of the type is defined something like
#define ID 73
#defin LPAREN 119
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, roll, counts[13];
for(i = 0; i < 13; i++)
counts[i] = 0;
for(i = 0; i < 10000; i++)
{
roll = random() % 6 + random() % 6 + 2;
counts[roll]++;
}
for(i = 2; i < 13; i++)
printf("There were %6d rolls of %4d ", counts[i], i);
return 0;
}
---------------------------------------------------------------
I had to put images separate because it was too big
Explanation / Answer
As per the question posted, the errors in the dice.C program is listed here.
Instead u have to use, rand( ) function to generate random numbers.
Otherwise u have to write your own function / macro named random( ).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.