私は、労働者や給与労働者の給料を計算する組合や構造を使用したプログラムを持っています。時間労働者の場合、彼らが働く時間は80時間未満でなければなりません。私はそれを私のコードで実装しましたが、私はこの警告を受け取り、それを修正する方法を知らない。多目的給与システムC
#include <stdio.h>
#include <ctype.h>
#define MAXSIZE 4000
union Employee { //union
struct HourlyPaid { //Struct for Hourly Workers
char name[20];
char Gender[20];
int HoursWorked;
float HourlyRate;
} HourlyPaid;
struct Salary { //struct for Salaried workers
char name[50];
int age;
float salary;
float bonus;
} Salary;
} Employee;
int main(void)
{
int i = 0;
int n = 0;
char option[2];
char s[MAXSIZE];
while(1)
{
puts("\nMULTIPURPOSE PAYROLL SYSTEM");
puts("Please Select an Option to Continue:");
puts("Option A: Calculating Pay for an HOURLY worker");
puts("Option B: Calculating Pay for an SALARIED worker\n");
puts("PRESS ANY OTHER BUTTON TO EXIT\n");
fgets(option, MAXSIZE, stdin);
//putchar(option);
if((option[0]=='a')||(option[0]=='A')) //Condition for Hourly Workers
{
puts("Please enter how many salaries you wish to input:\t");
scanf("%d", &n);
struct HourlyPaid x[n];
for(i = 0; i < n; i++)
{
fputs("Enter Name: ", stdout);
scanf("%s", x[i].name);
fputs("Enter Gender: ", stdout);
scanf("%s", x[i].Gender);
fputs("Enter Hours Worked: ", stdout);
scanf("%d", &x[i].HoursWorked);
fputs("Enter Hourly Rate: ", stdout);
scanf("%f", &x[i].HourlyRate);
}
if (&x[i].HoursWorked > 80)
{
puts ("Sorry please enter a value less than 80 for hours worked");
}
else
for (i = 0; i < n; i++)
{
printf("\n\tCalculated Salary #%d\n", (i+1));
puts("\t===============================");
printf("\n\tName %d.............%s \n", (i+1),x[i].name);
printf("\tGender %d...........%s \n", (i+1), x[i].Gender);
printf("\tHours Worked %d.....%d \n", (i+1), x[i].HoursWorked);
printf("\tHourly Rate %d......%.2f \n", (i+1), x[i].HourlyRate);
printf("\n\tTotal Salary %d.....%.2f \n", (i+1), (x[i].HourlyRate*x[i].HoursWorked));
puts("\t===============================");
} //End of for
} //End of if
else if((option[0]=='b')||(option[0]=='B')) //Condition for Salaried Workers
{
puts("Please enter how many salaries you wish to input:\t");
scanf("%d", &n);
struct Salary x[n];
//int i;
for(i = 0; i < n; i++)
{
printf("Enter Name %d: ", i+1);
scanf("%s", x[i].name);
printf("Enter Age %d: ", i+1);
scanf("%d", &x[i].age);
printf("Enter Salary %d: ", i+1);
scanf("%f", &x[i].salary);
printf("Enter Bonus %d: ", i+1);
scanf("%f", &x[i].bonus);
}
for (i = 0; i < n; i++)
{
printf("\n\tCalculated Salary #%d\n", (i+1));
puts("\t============================");
printf("\n\tName %d is..........%s \n", (i+1),x[i].name);
printf("\tAge %d is...........%d \n", (i+1), x[i].age);
printf("\tSalary %d is........%.2f \n", (i+1), x[i].salary);
printf("\tBonus %d is.........%.2f \n", (i+1), x[i].bonus);
printf("\n\tTotal Pay %d is.....%.2f \n", (i+1), (x[i].bonus+x[i].salary));
puts("\t============================");
}
} //End of else if
else
{
return 0;
}
fgets(option, MAXSIZE, stdin);
} //End of While
} //End of Main
なぜ 'x'の前に'& 'をつけていますか?あなたはポインタを使うことを意味しますか?あなたが 'if(x [i] .HoursWorked> 80)'を必要とすると思います。 – bansi
@bansi住所記号を削除するとif文は機能しません。 –
あなたはまた、混乱したループを持っています。 'if ....'ブロックは 'for'ループの中になければなりません。それ以外の場合は、常に第n + 1番目の値を確認します – bansi