Answered You can hire a professional tutor to get the answer.

QUESTION

I need to display the lowest of 2 numbers and message if numbers are equal. I am getting an error for illegal else without matching if.

I need to display the lowest of 2 numbers and message if numbers are equal. I am getting an error for illegal else without matching if. This is for C++ Visual Studio

#include<iostream>

using namespace std;

int main()

{

//Display description of program

cout<<"You will be asked to enter two numbers."<<endl<<

"The smallest value will be displayed or a message if they are the same"

<<endl<<endl;

//Prompt the user for the first number

int firstNum, secondNum, smallestNum;

cout<<"Please enter a numeric value: ";

cin>>firstNum;

//Prompt the user for the second number

cout<<"Please enter a numeric value: ";

cin>>secondNum;

cout<<endl<<endl;

//If second number is less than first number display second number

if(firstNum>secondNum)

{

smallestNum=secondNum;

}

cout<<"The smallest value is: "<<smallestNum<<endl;

//If first number is less than second number display first number

if(firstNum<secondNum)

{

smallestNum=firstNum;

cout<<"The smallest value is: "<<smallestNum<<endl;

//Else both numbers are equal

else(firstNum==secondNum);

cout<<"The numbers are equal: "<<firstNum<< ","<<secondNum<<endl;

}

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question