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

Recommended Answers

All 8 Replies

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.

i tried it but it still didn't ........

So, show your errors. Just saying it doesn't compile isn't helpful.

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

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... :-)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.