Hello!
I'm new to C and am working on a problem I was hoping to get some help. I am trying to create a survey asking a group of people how they liked a new product on a scale of x to y (these must be defined as Macros and must be able to accept negative numbers). The program outputs garbage values for my negative values instead of 0's. I'm sure it is an easy fix? I would love constructive criticism on my code as a whole too. Thanks. Code is as follows...
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_RESPONSE_VALUE 5
#define MIN_RESPONSE_VALUE -5
#define MAX_RESPONDENTS 5
#define ERROR_EXIT 3
int main(void)
{
int responsevalue[ MAX_RESPONSE_VALUE - MIN_RESPONSE_VALUE + 1 ] = {0};
int temp = 0;
int errorcounter = 0;
int usercounter = 1;
int printloop;
do
{
printf("PERSON NUMBER %d, How did you like our new product?\n", usercounter);
printf("Please enter a number on a scale of %d to %d,\n", MIN_RESPONSE_VALUE, MAX_RESPONSE_VALUE);
printf("Where %d is \"I Hated It!\" and %d is \"I Loved It!\"\n", MIN_RESPONSE_VALUE, MAX_RESPONSE_VALUE);
printf("(To exit program early, Please enter %d Out Of Range responses.)\n: ", ERROR_EXIT);
scanf("%d", &temp);
printf("\nThank you.\n\n");
if (temp >= MIN_RESPONSE_VALUE && temp <= MAX_RESPONSE_VALUE)
{
responsevalue[ temp - 1 ]++;
usercounter++;
}
else
{
printf("Error: Value out of range. Try Again.\n\n");
errorcounter++;
}
}
while (errorcounter < ERROR_EXIT && usercounter <= MAX_RESPONDENTS);
printf("Here are your results!\n\nRATING # OF RESPONSES\n\n");
for(printloop = MIN_RESPONSE_VALUE - 1; printloop < MAX_RESPONSE_VALUE; printloop++)
printf("%d %d\n", printloop + 1, responsevalue[printloop]);
return(EXIT_SUCCESS);
}