Hi. I'm an -absolute newbie- and I'm trying to write a calculator in C++. I use Dev++.
I currently have the code (below) that asks the user for 2 numbers and an operation and adds 'em up, simple right? Well, whenever I run the program and type in whatever, it just closes.
#include <iostream>
#include <cmath>
#include <cstdio>
int main()
{
usingnamespace std;
int Number1;
int Number2;
string Operation;
cout << "Welcome to the calculator!" << endl;
cout << "Enter your first number: ";
cin >> Number1;
cout << "Enter your second number: ";
cin >> Number2;
cout << "Operation (*,/,+,-): ";
cin >> Operation;
if (Operation == "+"){
cout << "The result is: " << Number1 + Number2;}
getchar();
return 0;
}
I've tried system("pause") , getchar() and cin.get() and NOTHING WORKS! If someone could please look at my code and tell me what I'm doing wrong, I would really appreciate it!
#include <iostream>
#include <string>
int main()
{
int Number1;
int Number2;
std::string Operation;
std::cout << "Welcome to the calculator!" << std::endl;
std::cout << "Enter your first number: ";
std::cin >> Number1;
std::cout << "Enter your second number: ";
std::cin >> Number2;
std::cout << "Operation (*,/,+,-): ";
std::cin >> Operation;
if (Operation == "+"){
std::cout << "The result is: " << Number1 + Number2<<std::endl;}
std::cin.ignore();
std::cout<<"Press Enter Key To Exit";
std::cin.ignore();
return 0;
}