hey can any 1 help me out here coz i am new to c++ and have couple of errors

Using a program that gets the product of even numbers and sum of odd numbers between 1000 and 100, demonstrate the syntax and implementation of the different types of loops.

have like 6 errors

main(void)
{
  inti,sum=0,prod=2;
  for(i=1000;i<=100;i--)
 {
  if(i%2==0)
  {
   product=product*1;
  }
   else
   {
	 sum=sum-i
   } 
 }
  printf("the product is %d",prod);
  printf("the sum is %d",sum);
};
what wrong have i done

error C2065: 'inti' : undeclared identifier
error C2065: 'sum' : undeclared identifier
error C2065: 'prod' : undeclared identifier
error C2065: 'i' : undeclared identifier
error C2065: 'product' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'i'
warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.

What do you think you have wrong? Your compiler is telling you the whole story. Did you even look at your code before you tried to compile it?

What I can see right off the bat:

  1. There are no headers #included. You can't access any library functions without including the correct header(s).
  2. Your main() is not properly declared, it's an implied int, which is a deprecated practice, you should be explicit.
  3. On Line 3, you forgot the (space) character between the int dataType and your variable called 'i'.
  4. Your for loop is based on a decrementing index, but only runs if the index is less than the lowest value, which causes it to never run.
  5. Your mathematical/algebraic equations do not reflect the action(s) required by the parameters of the assignment.

I'm sure there are more problems, but that should get you started.

Edited 5 Years Ago by Fbody: n/a

I think the syntax is wrong also.printf is for c programming.c++ is using cout.am i correct?

If converting C code to Object Oriented C++ code, cout is an appropriate choice. However, because C++ is a superset of C, printf() is acceptable in C++ as well.

Unfortunately, many C++ classes force their members to learn the C subset before they start showing them the full OOP parts of the C++ syntax. I don't think it's wrong per se, because they should learn it. But it doesn't leave much time to cover topics that are strictly C++.

This article has been dead for over six months. Start a new discussion instead.