+ 3

Guys i need help with c++

How can i write a program that reads 2 integers and add the even numbers between them?

1st Dec 2019, 5:30 PM
Mhamad
Mhamad - avatar
10 Answers
+ 2
First of all your logic is not properly implemented. int e=x; gives error becuase you need to give value to x before assinging.. && with if() not a proper syntax... And some more.. Ok see this code int main() { int x,y,sum=0; cout<<"enter 2 numbers"; cin>>x>>y; if(x%2!=0) x++; while(x<=y) { sum=sum+x; x=x+2; } cout<<"\nsum of even numbers between x and y is "<<sum; } input: 2 8 output: 20 //2+4+6+8=20 is it what you want?
1st Dec 2019, 6:59 PM
Jayakrishna 🇮🇳
+ 7
What have you tried so far?
3rd Dec 2019, 8:43 AM
Rahul Mangwani
Rahul Mangwani - avatar
+ 4
Think and Try to do self.
1st Dec 2019, 5:41 PM
A͢J
A͢J - avatar
+ 3
Why don't you give it a try yourself first? Study the tutorial for a bit, try everything out. Reread the notes you made when your teacher explained loops to you. And then try to write that program and show us! (If we see an honest attempt, we're likely to assist.)
1st Dec 2019, 5:41 PM
HonFu
HonFu - avatar
+ 3
Then where is your problem show us.
1st Dec 2019, 5:45 PM
A͢J
A͢J - avatar
+ 1
I already did that
1st Dec 2019, 5:44 PM
Mhamad
Mhamad - avatar
+ 1
i’ll show u my program but i dont know why its not runing
1st Dec 2019, 5:44 PM
Mhamad
Mhamad - avatar
1st Dec 2019, 6:00 PM
Mhamad
Mhamad - avatar
+ 1
thank yoh very much❤️
1st Dec 2019, 8:22 PM
Mhamad
Mhamad - avatar
31st Dec 2019, 12:49 PM
🅢🅣🅞🅝🅔 🅛🅞🅝🅖
🅢🅣🅞🅝🅔 🅛🅞🅝🅖 - avatar