calculator wont work

#include <iostream>
#include <string>
#include <Windows.h>
#include <cmath>
using namespace std;

int main()
{
std::string input;
cout << "Choose arithmetic: Addition or Subtraction or Multiply or Divison " << endl;
cin >> input;

if(input == "Addition")
{
int first;
cout << "Enter the first number: " ;
cin >> first ;

int second;
cout << "Enter the second number: " ;
cin >> second ;

int sum = first + second;
cout << "The sum of these numbers is: " << sum << '\n' ;
Sleep(20000);
}

if(input == "Subtraction")
{
int first;
cout << "Enter the first number: " ;
cin >> first ;

int second;
cout << "Enter the second number: " ;
cin >> second ;

int diff = first - second;
cout << "The difference of these numbers is: " << diff << '\n' ;
Sleep(20000);

}
if(input=="Multipy")
{
int first;
cout << "Enter the first number: " ;
cin >> first;

int second;
cout << "Enter the second number: ";
cin >> second;

int diff = first * second;
cout << "The difference of these numbers is: " << diff << '\n' ;
Sleep(200000);
}

if(input=="Divison")
{
int first;
cout << "Enter the first number: " ;
cin >> first;

int second;
cout << "Enter the second number: ";
cin >> second;

int d = first / second;
cout << "The difference of these numbers is: " << d << endl;
Sleep(20000);
}
}
Just from a quick glance I'll point out things that are kind of setting red flags in my head. I wont bother to shove this into my compiler and figure it out.
1: You declared main as int and the compiler is expecting int.

2: You do not need to type std::string to make a string when you already have the using namespace std;

3: string itself is not a sequence of characters. String is actually a class that has specified sections for variables so by comparing a string class to a string literal(Representing string inside source code with "" operators) you're actually comparing everything inside of string including it's iterators, etc, to that string literal so you wont get any accuracy out of that.

4: If you wish to get the string character data you set it to then use the c_str() function that's inside of the string class so it's string.c_str(). This returns char * to the sequence of characters you have inside that string.

5: You don't need the cmath to include basic operator like + = - / %

Hope this helps.
Last edited on
Topic archived. No new replies allowed.