的main.cpp函數傳值與多個字符串作爲參數
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "function.h"
extern void CalcTax(float Gross, float Deffered, float *FedTax, float *StateTax, float *SSITax);
int main(void)
{
float FedTax, StateTax, SSITax, hours, payrate, defr;
char lastname, firstname;
EmployeeData(&lastname, &firstname, &hours, &payrate, &defr);
printf("%s\n", &lastname);
printf("%s\n", &firstname);
CalcTax(CalcGross(hours, payrate), defr, &FedTax, &StateTax, &SSITax);
printf("Your Gross is: %f\n", CalcGross(hours, payrate));
printf("the Federal Tax is %f\n",FedTax);
printf("the State Tax is %f\n",StateTax);
printf("the SSI Tax is %f\n",SSITax);
return 0;
}
void EmployeeData(char *lastname, char *firstname, float *hours, float *payrate, float *defr)
{
printf("last name?\n");
scanf("%s", lastname);
printf("first name?\n");
scanf("%s", firstname);
printf("hours?\n");
scanf("%f",hours);
printf("payrate?\n");
scanf("%f",payrate);
printf("defr?\n");
scanf("%f",defr);
}
有人可以幫我這個代碼,我試圖讓姓氏和名字輸入,並把它傳遞給主爲字符串。但是,當我運行上面的代碼時,我只能得到隨機字母,並且只有一個或兩個字母一次不是全名。我將不勝感激任何幫助。