~~Code Check~~

Hello, I am JUST starting C++. Im 14 and I know this code needs work, and was wondering if anyone would be willing to check the code and tell me what needs to be done, so I can learn right. This is not finished quite yet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include <iostream>
using namespace std;

int main()
{
    string mostRecentFunction;
    float answer;
    float x;
    float y;
    cout << "Welcome to the calculator! your most recent function was: "<< mostRecentFunction << "\n\n";
    cout << "Would you like to add or subtract?\n\n";
    cin >> mostRecentFunction;

    if(mostRecentFunction == "Subtract"||"subtract")
    {
        cout<<"\n\nInsert the number you want to have subtracted\n\n";
        cin >> x;

        cout << "\n\nInsert the amount you want subtracted\n\n";
        cin >> y;

        answer = x - y;
        cout <<"\n\n" << x << " - " << y << " is " << answer<<endl;

    }
    return 0;
}
Last edited on
#include <string> at the beginning
Last edited on
if(mostRecentFunction == "Subtract"||"subtract")

This doesn't do what you expect. See http://www.cplusplus.com/faq/beginners/logic/
@firedraco Thank you sooo much! :D
Topic archived. No new replies allowed.