Fahrenheit > Celcius

Hi, I am trying to create a little fun program that calculates Fahrenheit to Celcius and opposite, I've only created the Fahrenheit part for now. Thank you!

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

int main ()
{
    string a;
    string f;
    string c;
    cout << "Hello! Would you like too calculate Fahrenheit into Celcius? Or opposite? If you want fahrenheit > celcius then press 1, if opposite press 2." << endl;
    getline (cin, a);
    if (a == '1')    {
    
    cout << "How many fahrenheit do you want too calculate?" << endl;
    getline (cin, f);
    cout << f/1,8;
    } else {
    {
    cout << "How many celcius do you want to calculate?" << endl;
    }
    system("PAUSE");
    return 0;
}
I would suggest to not use string and getline here.
1
2
3
    string a;
    string f;
    string c;


would be better as
1
2
3
    char a;
    double f;
    double c;


1
2
    getline (cin, f);
    cout << f/1,8;


would become
1
2
    cin >> f;
    cout << (f - 32)/1.8;


@Chervil
Thank you very much! I just tried it and it still doesn't work? It says at the bottom[Warning] In function 'int main()': and: parse error at end of input.
Last edited on
It says at the bottom[Warning] In function 'int main()': and: parse error at end of input.

The original code had mismatched opening/closing braces { }. At the end of line 17, there is an opening brace { and then at the start of line 18 there is another opening brace. One of them has to go.


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
29
#include <iostream>
#include <string>
using namespace std;

int main ()
{
    char a;
    double f;
    double c;

    cout << "Hello! Would you like too calculate Fahrenheit into Celcius?\n"
            "Or opposite?\n" 
            "Fahrenheit > Celcius press 1,\n"
            "Celcius > Fahrenheit press 2." << endl;
    cin >> a;
    if (a == '1')   
    {
        cout << "How many fahrenheit do you want too calculate?" << endl;
        cin >> f;
        cout << (f - 32)/1.8;
    } 
    else 
    {
       cout << "How many celcius do you want to calculate?" << endl;
    }
    
    system("PAUSE");
    return 0;
}

Registered users can post here. Sign in or register to post.