Your indentation is all messy looking. Show the full source and explain the actual compiler errors you're getting.
Also, the code you posted seems really redundant, you do the same thing in both if statements (edit: Oh, it's not exactly the same, but it still seems weird), and you probably don't even need to check for parity if you know that i will always start as an even number, zero.
#include <iostream>
usingnamespace std;
int main()
{
int i=0;
int n;
cin>>n;
while (i<=n)
{
if (n%2==0)
{
i=i+1;
cout<<i<<endl;
i++;
}
if (n%2!=0)
{
i=i+2;
cout<<i<<endl;
i++;
}
}
system ("pause");
return 0;
}
Line 12 and 18: i is your loop index (i.e. number from 1 to n). Here you're checking if the limit is even or odd. You should be checking if i is even or odd.
As I read the instructions, you need to keep separate even and odd sums.
Line 5:
1 2 3 4 5 6 7 8 9 10 11
{ int even_sum = 0;
int odd_sum = 0;
// In place of line 14:
even_sum += i;
// In place of line 20:
odd_sum += i;
// After line 23:
i++;
// After line 24:
cout << "Sum of even numbers = " << even_sum << endl;
cout << "Sum of odd numbers = " << odd_sum << endl;
Line 14 and 20: You don't want to increment i inside the if statements. You should increment i once at the bottom of the loop (after line 23).
Line 18: You don't need an if statement here. Just an else.
If a number is not even, it must be odd.
Line 9: You're taking the modulo of n. Modulo of n (the limit) is going to be the same for all iterations of your loop. You want to test if i is even or odd.