Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> #include <stdlib.h> #include <time.h> int main (void) { int n

ID: 3922844 • Letter: #

Question

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (void)
{
   int num ;
   int>    int two =0;
   int three =0 ;
   int four = 0;
   int five = 0;
   int six =0 ;
   printf("ENTER HOW MANY TIMES YOU WANT TO ROLL THE DICE ");
   scanf("%d",&num);

   srand(time(NULL));
   int r;
   for (int i =0 ; i < num ; i++)
   {
       r= (rand()%6)+1;
      
       if (r==1)
           one++;
       else if(r==2)
           two++;
       else if(r==3)
           three++;
       else if(r==4)
           four++;
       else if(r==5)
           five++;
       else if(r==6)
           six++;

   }
   float t = one+two+three+four+five+six;

   printf(" FACE TIMES PERCENTAGE ");
   printf (" 1 %d %f ",one,100*one/t);
   printf (" 2 %d %f ",two,100*two/t);
   printf (" 3 %d %f ",three,100*three/t);
   printf (" 4 %d %f ",four,100*four/t);
   printf (" 5 %d %f ",five,100*five/t);
   printf (" 6 %d %f ",six,100*six/t);
   flushall();
   getchar();
   return 0;
}

This is my code in C language and its not copiling becuase of the for loop and i need it to work in gcc

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (void)
{
    int num ;
    int>     int two =0;
    int three =0 ;
    int four = 0;
    int five = 0;
    int six =0 ;
    printf("ENTER HOW MANY TIMES YOU WANT TO ROLL THE DICE ? ");

//Reading the number of time dice should be rolled.
    scanf("%d",&num);

    srand(time(NULL));
    int r;
    //loop iterating variable

   int i;

   .//Loop for throwing dice.
    for (i =0 ; i < num ; i++)
    {
        r= (rand()%6)+1;
      
        if (r==1)
            one++;
        else if(r==2)
            two++;
        else if(r==3)
            three++;
        else if(r==4)
            four++;
        else if(r==5)
            five++;
        else if(r==6)
            six++;

    }
    float t = one+two+three+four+five+six;

//Printing the output.

    printf(" FACE TIMES PERCENTAGE ");
    printf (" 1 %d %f ",one,100*one/t);
    printf (" 2 %d %f ",two,100*two/t);
    printf (" 3 %d %f ",three,100*three/t);
    printf (" 4 %d %f ",four,100*four/t);
    printf (" 5 %d %f ",five,100*five/t);
    printf (" 6 %d %f ",six,100*six/t);

//These two lines are waste of code.
    //flushall();
    //getchar();
    return 0;
}