这是我的主要模块。我有一些外部模块。
int main(void)
{
char ln[15+1];
char fn[10+1];
float fed,state,ssi;
float g,h,p,d,n;
InputEmployeeData(&ln[0],&fn[0],&h,&p,&d); // call 3.3
CalculateGross(h,p, &g); // call 3.4
computeTaxes(g,d,ADDR(fed),ADDR(state),ADDR(ssi)); // call 3.5
n = g-fed-state-ssi-d;
printf(" Fed = %8.2f\n",fed);
printf(" State = %8.2f\n",state);
printf(" SSI = %8.2f\n",ssi);
printf(" Net = %8.2f\n",n);
while(getchar() != '\n'); // flush(stdin)
return 0;
使用iostream的main.cpp
cout << " Fed = %8.2f\n" << fed;
cout << " State = %8.2f\n" << state;
cout << " SSI = %8.2f\n" << ssi;
cout << " Net = %8.2f\n" << n;
cin.sync();
//while(getchar() != '\n');
// flush(stdin)
return 0;
使用stdio.h inputemployeedata.cpp
//3.3
#include <stdio.h>
#define ADDR(var) &var
void InputEmployeeData(char *lastname,char *firstname, // 3.3
float *hours,float *payrate, float *defr);
void InputEmployeeData(char *lastname,char *firstname, // 3.3
float *hours,float *payrate, float *defr)
{
printf(" Enter the name ==> ");
scanf("%s%s",firstname,lastname);
printf(" Enter the hours and payrate ==> ");
scanf("%f%f",hours,payrate);
printf(" Enter the deferred earning amount ==> ");
scanf("%f",defr);
}
使用iostream inputemployeedata.cpp
{
cout << " Enter the name ==> ";
cin >> *firstname >> *lastname;
cout <<" Enter the hours and payrate ==> ";
cin >> *hours >> *payrate;
cout << " Enter the deferred earning amount ==> ";
cin >> *defr;
我不知道%8.2f
相当于cout
。我卡住了
答案 0 :(得分:-1)
TL; DR:%f表示正在打印的浮动。 %8.2f表示总字符数为8(或“%8.2f”中点之前的任何其他数字),以及点之后的2(或%f命令中点之后的任何其他数字)。
在这种情况下,可能会打印诸如“12345.78”之类的数字。
胡务?但8个数字!不,人物。点数包含在总计数中。
希望这有帮助!