使用函數原型創建程序時,出現了問題。它說:錯誤:語義問題從不兼容類型'void'分配'int'
Semantic issue Assigning to 'int' from incompatible type 'void'.
能否請你幫我解決這個問題?
這裏是我的代碼:
#include <stdio.h>
#include <math.h>
void powr(int);
int main(void) {
int n=1, sq, cu, quart, quint;
printf("Integer Square Cube Quartic Quintic\n");
do {
sq = powr(n); //here is the error line
cu = powr(n); //here is the error line
quart = powr(n); //here is the error line
quint = powr(n); //here is the error line
printf("%d %d %d %d %d\n", n, sq, cu, quart, quint);
n++;
}
while (n<=25);
return 0;
}
void powr(int n)
{
int a, cu, quart, quint;
a=pow(n,2);
cu=pow(n,3);
quart=pow(n,4);
quint=pow(n,2);
}
'powr'被定義爲void,如果你想以這種方式使用它,原型應該是'int powr(int n)' – amdixon
@amdixon和下一個4個返回值的問題。 :) –
不知道用戶在這裏做什麼。真的應該使用像sq = pow(n,2); ... quint = pow(n,5)這樣的std數學函數pow。 – amdixon