#include <iostream>
using namespace std;

int main()
{

	double firstNo;// first number is stored here
	double secondNo;
	double result;//variable for result when first and second number are operated upon
	double operation;// place to store the user's inputed operation
	

	// asks the user to choose the first number
	cout<< "Enter in the first Number ->";
	cin >> firstNo;

	// asks the user for the second number
	cout<< "Enter in the second Number -> ";
	cin >> secondNo;

	cout<< "which operation would you like to choose?\n";
	cout<< "(+) add, (-) sub, (*)multiply, (/) divide";
	cin >> operation;

	if (operation == '+'){
		result = firstNo + secondNo;
	cout<< "The sum of these two numbers are ->" << result << "\n";
	}
	else if (operation == '-'){
		result = firstNo - secondNo;
	cout<< "The difference of these two numbers are ->" << result << "\n";
	}
	else if (operation == '*'){
		result = firstNo * secondNo;
	cout<< "The product of these two numbers are ->" <<result << "\n";
	}
	else (operation == '/'); {
		result = firstNo / secondNo;
	cout<< " The quotient of these two numbers are ->" << result << "\n";
	}
	

	cout<<"/n";

return 0;

}

what ever operation i type in; say + or *, all that comes out is the quotient. I don't know where i messed up. i am guessing it is with the if else statements

Recommended Answers

All 6 Replies

For starters, operation is a double when it should be a char. You also have a rogue semicolon in your final else that ensures the quotient output will always occur.

oh snap, didn't catch that sorry. this is my first time programing and the class i am in uses savitch absolute c++, do you recommend supplementary materials for a beginner, because i am having difficulty with the text.

>this is my first time programing and the class i am in uses savitch absolute c++
You don't need to defend yourself. We all had to start somewhere, and making mistakes comes with the territory.

>do you recommend supplementary materials for a beginner, because i am having difficulty with the text.
I haven't read that one. Could you elaborate on what parts you're having trouble with?

commented: always a delight +2
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.