Need help debugging! ( C++ )
So I decided to learn C++ yesterday and while halfway through reading an e-book I decided to try out some of the things I learned.
I tried to make a really simple addition and subtraction calculator.
Everything seems to work fine when I run it and use the addition function however I cannot select other operations except addition.
The compiler's debugger doesn't give me any errors so I am confused.
Please help!
Here is my code
I use Code::blocks 16.01
Code:
#include <iostream>
#include <string>
using namespace std;
const string end ("end");
int add (float a, float b)
{
return (a + b);
}
int subtract (float a, float b)
{
return (a - b);
}
int main ()
{
string str;
float a, b;
float c;
while (str != "exit" or "Exit")
{
cout << "What operation whould you like to perform?\n";
cout << "Addition, Subraction, Exit\n";
cin >> str;
if (str == "addition" or "Addition" or "add" or "Add")
{
cout << "You have selected Addition.\n";
cout << "let : a + b = c\n";
cout << "Assign a value for a...";
cin >> a;
cout << "Assign a value for b...";
cin >> b;
c = add (a, b);
cout << a << "+" << b << "=" << c << "\n";
}
else if (str == "subtraction" or "Subtraction" or "sub" or "Sub")
{
cout << "You have selected Subtraction.\n";
cout << "let : a - b = c\n";
cout << "Assign a value for a...";
cin >> a;
cout << "Assign a value for b...";
cin >> b;
c = subtract(a, b);
cout << a << "-" << b << "=" << c << "\n";
}
else if (str != "exit")
{
cout << "Invalid operation.";
}
}
return 0;
}
Also if you could tell me some tips that would be great, since this is the first programming language I tried to learn!
