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

You need a loop construct:

int i;

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

something like that outa work.

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;
}

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;
}

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;
}

Edited 3 Years Ago by pyTony: fixed formating

if you wanted to go beyond the call of duty you could do one of these:

#include <iostream.h>
#include <stdlib.h>
void main()
{
 int MAX;
 cout<<"Enter a number to count by two to: ";
 cin>>MAX;
 for (int x = 0; x <= MAX; x++)
 {
  if (x % 2 == 0)
  {cout << x << endl;}
 }
 system("pause");
}
This article has been dead for over six months. Start a new discussion instead.