Do While Loop

I need help making this program work


#include <iostream>
using namespace std;

int main()

{

int x=0, evenSum=0, oddSum=0, num;



do
{
cout << "Please enter 10 integers : ";
cin >> num;


if(num % 2 == 0);
{
evenSum += num;
}
else
{
oddSum += num;
}
x++;

}While(x<10)
}
cout << "Even Sum : " << evenSum << endl;
cout << "Odd Sum : " << oddSum << endl;

return 0;
}
Last edited on
Original code with code tags to aid legibility :

[code]your code here[/code]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

int main()

{

    int x=0, evenSum=0, oddSum=0, num;



    do
    {
        cout << "Please enter 10 integers : ";
        cin >> num;


    if(num % 2 == 0);
    {
        evenSum += num;
    }
        else
    {
        oddSum += num;
    }
        x++;

    }While(x<10)
}
    cout << "Even Sum : " << evenSum << endl;
    cout << "Odd Sum : " << oddSum << endl;

    return 0;
}
Line 18: should not end with a semicolon.
Line 28: While must be all lower-case.
Line 28: must end with a semicolon.
Line 29: remove unmatched closing brace }

(also inconsistent indentation).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

int main()
{
    int x=0, evenSum=0, oddSum=0, num;

    do
    {
        cout << "Please enter 10 integers : ";
        cin >> num;

        if (num % 2 == 0)
        {
            evenSum += num;
        }
        else
        {
            oddSum += num;
        }
        x++;

    } while (x<10);

    cout << "Even Sum : " << evenSum << endl;
    cout << "Odd Sum :  " << oddSum  << endl;

}
Topic archived. No new replies allowed.