0

After inputting the hourly wage, the compiler spits out the first and second printf, what methods could I use to fix this? Feel free to give any other feedback if some of this code is sloppy, I'm pretty new to programming right now so I might just be making a lotta rookie moves.


struct employee
{
    char name[20];
    float hours; 
    float payrate;  
    float basepay;
    float overtimepay;
    float grosspay;
    float taxespaid;
    float netpay;
}; 

int prompt(struct employee *ptrfiveemployees);

int main()
{
    int ret;
    struct employee fiveemployees[5];
    for(int i = 0; i < 5; i++)
    {
        ret = prompt(&fiveemployees[i]);
        if(ret != 0)
        {
            printf("Error");
        }
    }
}

int prompt(struct employee *ptrfiveemployees)
{
        printf("Please enter the name of your employee.\n");
        fgets(ptrfiveemployees->name, 20, stdin);
        printf("Now enter the number of hours they worked.\n");
        scanf("%f", &(ptrfiveemployees->hours));
        printf("Now enter the hourly wage they are paid.\n");
        scanf("%f", &(ptrfiveemployees->payrate));
    
    return 0;
}



  • `prompt` will always return zero, what the check is for? – vmemmap Jul 29 '22 at 08:47
  • `prompt()` deals with a single employee. Start by naming the received pointer `pEmp`. Programmers aren't "paid by the pound" for their typing. Perhaps rename `prompt()` to be `getEmpInfo()`??? – Fe2O3 Jul 29 '22 at 08:51
  • You may want to read this: [What can I use for input conversion instead of scanf?](https://stackoverflow.com/q/58403537/12149471) – Andreas Wenzel Jul 29 '22 at 09:52
  • @Fe2O3 Good point! I usually don't name things very concisely until I actually am ready to turn my code in, maybe that should change from here on out – xyarion Jul 29 '22 at 18:01

0 Answers0