Hey all. I'm a beginner. Please somebody tell me what's wrong with the simple use of my else statement. The compiler says: "Error. Expected a statement."

// IfDemo.cpp : Defines the entry point for the console application.
//
// demonstration of IF statement

#include "stdafx.h"
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{

// first argument
	int nArg1;
	cout << "Enter arg1: ";
	cin >> nArg1;

// second argument
	int nArg2;
	cout << "Enter arg2 ";
	cin >> nArg2;

// now decide what to do
	if (nArg1 > nArg2);
		{
		cout << "Heck yeah arg1 is larger! \n\n";
		}
	else
		{
		cout << "Afraid not, my friend. Sorry! \n\n";
		}
	
		
	return 0;
}

y is there a ; after if statement in line 24?

yeah your problem is you have a ; after your if statment at line 24. apart from that it should work

The semi-colon after the if statement should be removed. May I add that for such a simple program you complicated it.

Why did he make it complicated? It looks pretty reasonable to me.

Didn't expect such a quick answer. That solved it. Thanks all!!!

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.