HELP for programming c++ (EXPECTED ; BEFORE STRING CONSTANT)

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
First, please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

That said, error message comes from this:
cout<<"SUMATORIA= "<<s<<endl"\n";
One can add whitespace to help readability:
1
2
3
cout << "SUMATORIA= "
  << s
  << endl"\n";

And now the error is on:
<< endl"\n";
In fact, the error is in the:
endl"\n"

What does that mean? Is there a typo or something?
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
Topic archived. No new replies allowed.