I'm working on a school activity and i need some help. I'm programming with vectors and i have a mistake, but i don't know why. This is it:
(1)#include <iostream>
(2)#include <math.h>
(3)using namespace std;
(4)int main ()
(5){
(6)float a[11], s, x; int i;
(7)for (i=1; i<=10; i++)
(8) {
(9) cout<<"a[ "<<i<<"]=";
(10) cin>>a[i];
(11) }
(12)s=0;
(13)
(14)i=1;
(15)do
(16) {
(17) s=s+pow(a[i],i);
(18) i=i+1;
(19) }
(20)while (i<=10);
(21)cout<<"SUMATORIA= "<<s<<endl"\n";
(22)return 0;
The mistake is this:
"expected ; before string constant (20)
Please, someone to help me
Ah, i realized that. Thank you
I noticed you put a semicolon after your while loop condition (line 20). Remove it, otherwise your program will go in an endless loop.
@lehti: the poor formatting of the post got you. The semicolon is where it should in:
13 14 15 16 17 18 19 20
|
s=0;
i=1;
do
{
s=s+pow(a[i],i);
i=i+1;
}
while (i<=10);
|
That is a
do while
-loop, not the
while
-loop.
(Almost fell for that trap myself.)
Last edited on