I'm just basically reading a book and messing around with the scripts they give me so I can understand what they're talking about, and here is the script (essencially word for word) however isn't working. What the program is supposed to do is (for example:)

"Enter two integers, and I will tell you the relationship they satisfy: 3 7

3 is not equal to 7
3 is less than 7
3 is less than or equal to 7"

Here is the code i'm messing with:

// Blarg.cpp : main project file.

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int num1;
	int num2;

	cout << "Enter two integers, and I will tell you/n"
		<< "the relationship the satisfy: ";
cin >> num1 >> num2; 

if (num1 == num2)
cout << num1 << "is equal to" << num2; endl;


if (num1 != num2)
cout << num1 << "is not equal to" << num2; endl;

if (num1 < num2)
cout << num1 << "is less than" << num2; endl;

if (num1 > num2)
cout << num1 << "is Greater than" << num2; endl;

if (num1 <= num2)
cout << num1 << "is less than or equal to" << num2; endl;

if (num1 >= num2)
cout << num1 << "is greater than or equal to" << num2; endl;

return 0;

}

And here is the error message:

------ Build started: Project: Blarg, Configuration: Debug Win32 ------
Compiling...
Blarg.cpp
.\Blarg.cpp(18) : warning C4551: function call missing argument list
.\Blarg.cpp(18) : error C2568: 'identifier' : unable to resolve function overload
.\Blarg.cpp(22) : warning C4551: function call missing argument list
.\Blarg.cpp(25) : warning C4551: function call missing argument list
.\Blarg.cpp(28) : warning C4551: function call missing argument list
.\Blarg.cpp(31) : warning C4551: function call missing argument list
.\Blarg.cpp(34) : warning C4551: function call missing argument list
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\Blarg\Blarg\Debug\BuildLog.htm"
Blarg - 1 error(s), 6 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

line 16 and all other similar lines. replace the semicolon before endl with << cout << num1 << "is equal to" << num2 << endl;

Okay, got it. Still getting an error, I'm not sure if I'm completely blind and somewhere in the script I wrote num(space)1 or num(space)2 but I don't see anything like that, anyway here is the updated code:

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int num1;
	int num2;

	cout << "Enter two integers, and I will tell you/n"
		<< "the relationship the satisfy: ";
cin >> num1 >> num2; 

if (num1 == num2)
cout << num1 << "is equal to" << num2 << endl;


if (num1 != num2)
cout << num1 << "is not equal to" << num2 << endl;

if (num1 < num2)
cout << num1 << "is less than" << num2 << endl;

if (num1 > num2)
cout << num1 << "is Greater than" << num2 << endl;

if (num1 <= num2)
cout << num1 << "is less than or equal to" << num << endl;

if (num1 >= num2)
cout << num1 << "is greater than or equal to" << num2 << endl;

return 0;

}

And the error message:

------ Build started: Project: Blarg, Configuration: Debug Win32 ------
Compiling...
Blarg.cpp
.\Blarg.cpp(31) : error C2065: 'num' : undeclared identifier
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\Blarg\Blarg\Debug\BuildLog.htm"
Blarg - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

if (num1 <= num2)
cout << num1 << "is less than or equal to" << num/*error here*/ << endl

Change that to num2 and I think you won't get any more errors.

Mmmm, Yeah I'm blind apparently.

Thank you, this is handled.

While we're semi on the topic, could someone please tell me what the difference between if{, else if{ and else{ is?

While we're semi on the topic, could someone please tell me what the difference between if{, else if{ and else{ is?

if(<condition>)
{
   //do something
}
else if(<other possible condition>)
{
  //do something else
}
else <if above conditions fail, then resort to this condition>
{
    //last resort if other conditions fail
}

else and else if can only be used immediately after an if.

if's can exist on their own, for example--

if(<condition>)
{
   //do something
}

if(<another condition>)
{
   /do something
}

--in which, neither if relies on each other. Basically both conditions can be executed if both are true, unlike the if-else statements above where only one of the conditions will be true.

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.