C++程序纠错 大家帮忙

来源:百度知道 编辑:UC知道 时间:2024/09/24 23:02:28
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double a;
double b;
int c;
a=100.00;
b=.01;
c=1;
while(c<=10;c++)
{
a=a*(1+b)^c;
cout<<a<<endl;
return 0;
}
}

while(c<=10)
{
c++;
.....
}

另外a*(1+b)^c需要单独实现。。譬如写成
int tempN()
{
int count = 1;
for(int i = 0; i < c; i++)
{
count *= (1+b);
}
return count*a;
}

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double a;
double b;
int c;
a=100.00;
b=.01;
c=1;
while(c<=10) //把c++;移动到下面
{
a=a*(1+b); //去掉^c
cout<<a<<endl;
c++;
return 0;
}
}

#include<iostream.h>
#include<math.h>
int main()
{
double a;
double b;
int c;
a=100.00;
b=.01;
c=1;
while(c<=10)
{
a=a*(1+b);
cout<<a<<endl;
c++;
}
}

将程序与一楼对比一下,你会发现运行结果会有差别的。

1、C++里没有乘方运算符,必须用一个系统函数pow(x,y),就是x的y次方。
2、while循环条件中不能有两条语句,只能是表示布尔条件的值。可以