Print Even Numbers

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2004
Posts: 8
Reputation: peter brown is an unknown quantity at this point 
Solved Threads: 0
peter brown peter brown is offline Offline
Newbie Poster

Print Even Numbers

 
1
  #1
Apr 12th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 1
Reputation: tortellini is an unknown quantity at this point 
Solved Threads: 0
tortellini tortellini is offline Offline
Newbie Poster

Re: C++ help with a PROGRAM

 
1
  #2
Apr 12th, 2004
You need a loop construct:

int i;

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

something like that outa work.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 8
Reputation: peter brown is an unknown quantity at this point 
Solved Threads: 0
peter brown peter brown is offline Offline
Newbie Poster

Re: C++ help with a PROGRAM

 
0
  #3
Apr 12th, 2004
tortellini
you are a miricle..
thank you peter
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 8
Reputation: peter brown is an unknown quantity at this point 
Solved Threads: 0
peter brown peter brown is offline Offline
Newbie Poster

It didnt work tortelli

 
0
  #4
Apr 12th, 2004
The C++ program I wanted you to help me with
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 8
Reputation: peter brown is an unknown quantity at this point 
Solved Threads: 0
peter brown peter brown is offline Offline
Newbie Poster

Re: It didnt work tortelli

 
0
  #5
Apr 12th, 2004
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;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 8
Reputation: peter brown is an unknown quantity at this point 
Solved Threads: 0
peter brown peter brown is offline Offline
Newbie Poster

Re: C++ help with a PROGRAM

 
0
  #6
Apr 12th, 2004
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;
}
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 28
Reputation: Bleek is an unknown quantity at this point 
Solved Threads: 0
Bleek Bleek is offline Offline
Light Poster

Re: C++ help with a PROGRAM

 
1
  #7
Apr 13th, 2004
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;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 8
Reputation: peter brown is an unknown quantity at this point 
Solved Threads: 0
peter brown peter brown is offline Offline
Newbie Poster

Re: C++ help with a PROGRAM

 
0
  #8
Apr 13th, 2004
Bleek thank you....

Peter Brown
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 219
Reputation: BountyX is an unknown quantity at this point 
Solved Threads: 7
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: C++ help with a PROGRAM

 
1
  #9
Apr 13th, 2004
if you wanted to go beyond the call of duty you could do one of these:
  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. }
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 28
Reputation: Bleek is an unknown quantity at this point 
Solved Threads: 0
Bleek Bleek is offline Offline
Light Poster

Re: C++ help with a PROGRAM

 
0
  #10
Apr 14th, 2004
for next time
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC