can someone give me a detailed explaination why this won't compile, thanks`

#include <iostream>
using namespace std;
int main () {
   int num1 = 5, num2 = 10;
   if (num1 < num2) { 
       cout<<”num1 is less than num2”;
   else cout<<”num1 is not less than num2”;
  }
   return 0;
}

Edited 2 Years Ago by yeyo_1

You are missing a couple of curly braces. Try this instead:

    #include <iostream>
    using namespace std;
    int main ()
    {
        int num1 = 5, num2 = 10;
        if (num1 < num2)
        {
            cout << ”num1 is less than num2” << endl;
        }
        else
        {
            cout << ”num1 is not less than num2” << endl;
        }
        return 0;
    }

Proper bracing of conditional statements and better indentation help a lot in avoiding this sort of problem.

Change those to this ".
I don't know what they called :-D

Edited 2 Years Ago by Sarkurd

Change those ” to this ".
I don't know what they called :-D

Good catch Sarkurd! He was using back-double-quotes instead of regular double quotes for the strings. My old eyes missed that... :-)

Edited 2 Years Ago by rubberman

I faced same problem after i copied an example from a book.
Thanks, now i know they are called back double quotes :-D

This way also works:

#include <iostream>
#include <stdio.h>
using namespace std;

int main () {

  int num1 = 5, num2 = 10;

  if (num1 < num2)    
     printf("%d is less than %d", num1, num2);
  else
     printf("%d isn't less than %d", num1, num2);
  return 0;

}

@Sarkurd thanks for the deligent lookthrough.......and @rubberman thanks for the correction

Edited 2 Years Ago by yeyo_1

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