What'd I do this time ...

Ok so I was going to make a conversion program which, when executed gave you an option of 1 or 2 (so original I know) so I had a integer (int) which checked which one you typed (1||2) but whenever I have it run if I type a character like "a" it converts it to a number :(
by the way I'm going to make functions for conversion later.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    string choice;
    cout << "Type 1 to convert Fahrenheit to Celsius\n";
    cout << "Type 2 to convert Celsius to Fahrenheit\n";
    cin >> choice;
    if (choice != ("1" || "2")){
       cout << "Please enter a valid number";
       cin.get();
    }else if (choice == "1"){
       //Farenheit to Celsius
    }else if (choice == "2"){
       //Celsius to Fahrenheit
    }      
          
    cin.get();
    return 0;
}



btw again this is what meh debugger outputs
expected primary-expression before '=' token
Last edited on
hmm ... I read through it and it didn't work :( however I re-did the if statement and it worked ... but not for 2 but then I remembered the article you sent me :) and fixed it up for 2 thank you :)

here is meh finished code:
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 <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    string choice;
    cout << "Type 1 to convert Fahrenheit to Celsius\n";
    cout << "Type 2 to convert Celsius to Fahrenheit\n";
    cin >> choice;
    if (choice != "1" && choice != "2"){
       cout << "Please enter a valid number.";
       cin.get();
    }else if (choice == "1"){
       //Farenheit to Celsius
       cout << "F to C";
       cin.get();
    }else if (choice == "2"){
       //Celsius to Fahrenheit
       cout << "C to F";
       cin.get();
    }      

          
    cin.get();
    return 0;
}


btw what does this emoticon look like to you? :9

And thank you again :)
Like someone shot you in the lip and you're trying to smile.
One of my programming teachers called what you're doing "scratching your left ear with your right hand".
1
2
3
4
if (choice == "1"){
}else if (choice == "2"){
}else{
}
Topic archived. No new replies allowed.