//Code 1
#include<iostream>
#include<stdlib.h>
using namespace std;
main()
{
int sum ;
int number;
int UpperLimit ;
sum = 0;
number = 1;
cout << " Please enter the upper limit for which you want the sum ";
cin >> UpperLimit;
while (number <= UpperLimit)
{
if (number % 2 == 0)
{
sum = sum + number;
number = number + 1;
}
}
cout << " The sum of all even integer between 1 and " << UpperLimit << " is" << sum;
system("pause");
return 0;
******************************************************
//Code 2
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int number ;
int factorial ;
factorial = 1 ;
cout << "Enter the number of Factorial" ;
cin >> number ;
while ( number >= 1 )
{
factorial = factorial * number ;
number = number – 1;
}
cout << "Factorial is" << factorial ;
system("pause");
return 0;
}
If you're talking about the compiler error in the second code, replace number = number – 1;
with number = number - 1;.
(It's hard to see the difference here, but you seem to be using a different character other than the dash (-) for your minus sign.)
In your first code, delete your #include <iostream> line and retype it (there's something weird going on in that line).
Then, it should be int main(), not main(), and you have an infinite loop in your code (just saying).