I do not understand why I am receiving this exception every time I attempt to enter a value for name.
This is the exception I get, Exception thrown at 0x0F59B211 (ucrtbased.dll) in Program3.exe: 0xC0000005: Access violation writing location 0xFFFFFFCC.
If there is a handler for this exception, the program may be safely continued.
I am new to c so please explain thoroughly.
#include <stdio.h>
#include <string.h>
int askUser(char name[5][16],float hourlyRate[5],float hoursWorked[5])
{
int counter = 0;
for (int i = 0; i < 5; i++)
{
printf("enter name: ");
scanf_s("%15s", name[i], 16);
if (strcmp(name[i], "-1") == 0)
break;
printf("enter hourly rate: ");
scanf_s("%f", &hourlyRate[i]);
if (hourlyRate[i] == -1)
break;
printf("enter hours worked: ");
scanf_s("%f", &hoursWorked[i]);
if (hoursWorked[i] == -1)
break;
counter++;
}
return counter;
}
void main()
{
const float OVERTIMEHOURS = 40.0f;
const float OVERTIMERATE = 1.5f;
const float TAX = 0.20f;
char name[5][16] = { "", "", "", "", "" };
float hourlyRate[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float hoursWorked[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float amountPaid[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float basePay[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float overPay[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float taxPaid[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float netPay[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float overTime[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float totalPaid = 0.0f;
int counter = 0;
counter = askUser(name[5][16], &hourlyRate[5], &hoursWorked[5]);
}