• Forum
  • Lounge
  • .cpp [Error] expected ';' before numeric

 
.cpp [Error] expected ';' before numeric constant

Please find error in the following codes:

//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;
}
closed account (N36fSL3A)
We will not do your homework for you. Tell us your problem, and we will help.

It couldn't hurt to use code tags or post the topic in the right forums either.
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).
Topic archived. No new replies allowed.