Hello everyone,
This is a program which asks the user 10 times to give a rating to a television show on a scale of 1 to 10(inclusive). Am posting the before and after code. There is no problem with the before code.
Before code
Code:
#include <stdio.h>
int main ()
{
int ask, i, ratingcounter[i], response, display ;
for (i = 1; i <= 10; i++)
ratingcounter[i] = 0 ;
printf ("Rate the television show on a scale of 1 to 10\n\n") ;
for (ask = 1; ask <= 10; ask++)
{
scanf ("%i", &response) ;
printf ("\n") ;
if (response < 1 || response > 10)
printf ("Bad response\n\n") ;
else
ratingcounter[response]++ ;
}
printf ("Rating Number of responses\n") ;
printf ("------ -------------------\n\n") ;
for (display = 1; display <= 10; display++)
printf (" %i %i\n\n", display, ratingcounter[display]) ;
return 0 ;
}
In the after code, I've added a new variable which increases the bad responses.
I've made the changes that I've made in bold for easier view.
After code
Code:
#include <stdio.h>
int main ()
{
int ask, i, ratingcounter[i], response, display, br = 0 ;
for (i = 1; i <= 10; i++)
ratingcounter[i] = 0 ;
printf ("Rate the television show on a scale of 1 to 10\n\n") ;
for (ask = 1; ask <= 10; ask++)
{
scanf ("%i", &response) ;
printf ("\n") ;
if (response < 1 || response > 10)
{
printf ("Bad response\n\n") ;
br++ ;
}
else
ratingcounter[response]++ ;
}
printf ("Rating Number of responses\n") ;
printf ("------ -------------------\n\n") ;
for (display = 1; display <= 10; display++)
printf (" %i %i\n\n", display, ratingcounter[display]) ;
printf ("\nTotal bad responses = %i\n\n", br) ;
return 0 ;
}
I've attached the error that I get after I compile/run the after code.
What is wrong here, please help.