do while

Hi there! I tried to run this code into codeblocks but it tells me i have some errors. Can you please help me to fix it? thank you!!


#include <iostream>

using namespace std;

int main(void)
{
int i=0,S=0;
do {
S=S+2;
i=i+2;
}
while(S<20 && i<20)
cout<<"i="<<i;
cout<<"S="<<S;
}
}
Last edited on
Please, always post exact error you are getting.

You forgot semicolon after while line.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

using namespace std;

int main(void)
{
int i=0,S=0;
do {
S=S+2;
i=i+2;
}
while(S<20 && i<20)  ///; missing semicolon like MiiNiPaa said
cout<<"i="<<i;
cout<<"S="<<S;
}
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;

int main(void)
{
int i=0,S=0;
do {
S=S+2;
i=i+2;
}
while(S<20 && i<20);
cout<<"i="<<i;
cout<<"\nS="<<S;
}
i=20 s=20
Last edited on
Topic archived. No new replies allowed.