I am a complete beginner at c so please give me advice that is as simple as possible. I have two questions. How do you use scanf in a function with pointers because my program is not working at all. Also, how do you write functions that uses values from another function. For example I have to write a function that asks for employee name, hours worked, and hourly rate. And then I have to write another function that uses that information to calculate gross pay and overtime pay. This is the scanf code I wrote so far:
#include <stdio.h>
#include <stdlib.h>
int employeedata(char *ch, float *x, float *y)
{
printf("Enter your name:\n");
scanf_s("%s", &ch);
printf("Enter your hourly rate:\n");
scanf_s("%f", &x);
printf("Enter number of hours worked:\n");
//variables
scanf_s("%f", &y);
}
int main() {
float rate[5], hours[5];
float overtimerate = 1.5;
char name[5][20];
int loop;
//loop 5 times
for (loop = 0; loop < 5; loop++)
{
//call function
employeedata(name[loop], &rate[loop], &hours[loop]);
//use if to break out of loop after input if -1 is entered
if (strcmp(name, "-1") == 0)
break;
if (rate[loop] == -1)
break;
if (hours[loop] == -1)
break;
}
system("pause");
return 0;
}