我的 C++ 程序有一个除法运算,在 using 命名空间和内容之后如下所示。
cout<<"Please type the data";
cin>> a;
z = a/4;
cout<<"The answer is"<< z;
Run Code Online (Sandbox Code Playgroud)
如果我输入一个可以整除的数字,程序会给出准确的数字
前任。a=8,z=4
但是当涉及到不能被4直接整除的数字时,它显示的结果如下所示
a=54
b=13 // 真正的答案是 13.5
它忽略小数点之前的数字。如何在结果中包含小数点前的所有数字(或至少到小数点后 4 位)?
请帮忙。
我有一个运行时错误,它从数组写入的数据多于其打印ID,AverageMarks和Status:
宣言及其功能
char StudentStatus[10][7];
for(x=0;x<10;x++)
{
fprintf(OutputFile,"%d\t\t%d\t\t\t%s\n",StudentID[x],StudentAvg[x],StudentStatus[x]);
}
Run Code Online (Sandbox Code Playgroud)
但是当它打印出来时
100 77 DismissActive
101 85 Active
102 88 Active
103 86 Active
104 85 Active
105 84 Active
106 84 Active
107 82 Active
108 92 Active
109 75 Dismiss
数组的填充方式:
for(x=0;x<NumOfStudent;x++)
{
if(StudentAvg[x]>80)
{
strcpy(StudentStatus[x],"Active");
printf(". ");
}
else
{
strcpy(StudentStatus[x],"Dismiss");
printf(". ");
}
}
Run Code Online (Sandbox Code Playgroud)
其他声明工作正常,但第一个声明真的很麻烦我.我错误编码的任何建议?