943,390 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 14943
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 12th, 2004
1

Print Even Numbers

Expand Post »
I have a problem, I want to create a program in C++.
A simple program displaying all even number between 1 and 100, (such as 2, 4, 6, 8 etc.) in an out put. Can you tell me what wrong. Something like this.
#include <iostream.h>
int main()
{
int num1=1;
int num2=2
if(num1<num2
{
cout << num1<<num2*2endl;
num1=num1+1;
num2=num2*2;
}
return 0;
}

Can you help me with this. What do you think?
You help is appreciated.....Peter
Similar Threads
Reputation Points: 12
Solved Threads: 0
Newbie Poster
peter brown is offline Offline
8 posts
since Apr 2004
Apr 12th, 2004
1

Re: C++ help with a PROGRAM

You need a loop construct:

int i;

for (i = 0; i <= 100; i += 2) {
//print i
}

something like that outa work.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
tortellini is offline Offline
1 posts
since Apr 2004
Apr 12th, 2004
0

Re: C++ help with a PROGRAM

tortellini
you are a miricle..
thank you peter
Reputation Points: 12
Solved Threads: 0
Newbie Poster
peter brown is offline Offline
8 posts
since Apr 2004
Apr 12th, 2004
0

It didnt work tortelli

The C++ program I wanted you to help me with
Reputation Points: 12
Solved Threads: 0
Newbie Poster
peter brown is offline Offline
8 posts
since Apr 2004
Apr 12th, 2004
0

Re: It didnt work tortelli

I need help in creating a C++ program, to display all even numbers between 1 and 100, (such as 2, 4, 6, 8 etc). The program would go something like:

#include <iostream.h>

int main ( )
{
int num1=1;
int num2=2;

if (num1=0; num2<100; num2=1=2){
cout<<
}
return 0;
}
Reputation Points: 12
Solved Threads: 0
Newbie Poster
peter brown is offline Offline
8 posts
since Apr 2004
Apr 12th, 2004
0

Re: C++ help with a PROGRAM

Hello, Iam trying to create a program, that would display all even number between 1 and 100, (such as 2,4,6,8 etc.). The program would be in C++, and it would go something like:

//comments
//date
#include <iostream.h>

int main( )
{
int num1=0;
int num2=2*2;

if( num1 = num2)
cout<<

return 0;
}
Reputation Points: 12
Solved Threads: 0
Newbie Poster
peter brown is offline Offline
8 posts
since Apr 2004
Apr 13th, 2004
1

Re: C++ help with a PROGRAM

thats easy...

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
int x = 0;

while (x < 101)
{
cout << x << endl;
x = x + 2;
}
system("pause");

return 0;
}
Reputation Points: 45
Solved Threads: 0
Light Poster
Bleek is offline Offline
28 posts
since Mar 2004
Apr 13th, 2004
0

Re: C++ help with a PROGRAM

Bleek thank you....

Peter Brown
Reputation Points: 12
Solved Threads: 0
Newbie Poster
peter brown is offline Offline
8 posts
since Apr 2004
Apr 13th, 2004
1

Re: C++ help with a PROGRAM

if you wanted to go beyond the call of duty you could do one of these:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. void main()
  4. {
  5. int MAX;
  6. cout<<"Enter a number to count by two to: ";
  7. cin>>MAX;
  8. for (int x = 0; x <= MAX; x++)
  9. {
  10. if (x % 2 == 0)
  11. {cout << x << endl;}
  12. }
  13. system("pause");
  14. }
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004
Apr 14th, 2004
0

Re: C++ help with a PROGRAM

for next time
Reputation Points: 45
Solved Threads: 0
Light Poster
Bleek is offline Offline
28 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Build curva in VC++ 6.0
Next Thread in C++ Forum Timeline: factorial fuctions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC