will calculate and display the sum of all even even numbers from 2 to n, where n is a positive number inputted by the user..what will i do and what is the expression of that???
hoceandress 0 Newbie Poster
Recommended Answers
Jump to PostSo, you are having trouble with language constructs or logic?
Jump to Post#include <iostream.h>
#include <conio.h>main()
{
clrscr();
int e,n,x;
e=1;
cout<<"n: ";
cin>>n;do
{
e=e%2;
cout<<"\nn: "<<e;} while ((e<=n) && (e++));
this my problem i can't fix it!! where n is a positive number inputted by the user. display the sum of all even numbers form 2 to …
Jump to PostMinor point: don't forget that in C++ you must initialise your variable outside the for loop:
int e; for (e=2; e<=n; e+=2)
That's incorrect. It was only required in C89/90. C++ never had such requirement. Even C99 removes this restriction.
All 10 Replies
SpS 34 Posting Pro
hoceandress 0 Newbie Poster
darkagn 315 Veteran Poster Featured Poster
jsap 0 Newbie Poster
SpS 34 Posting Pro
dougy83 74 Posting Whiz in Training
darkagn 315 Veteran Poster Featured Poster
hoceandress 0 Newbie Poster
SpS 34 Posting Pro
darkagn 315 Veteran Poster Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.