expected unqualified id before '{' token

I am facing two errors on line 4. using Dev++ please help me. I have to submit this assignment and today is last date.

expected unqualified-id before '{' token
before '{' token
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  #include <iostream>
int main();

{
double f_temp, k_temp, c_temp, temp;
char ch, quit;
cout<< " *********** Temprature Conversion Calculator **************";
cout<< "\n\n Please enter the temprature unit for which you want the coverison ";
cout<< "\n 1. F for Fahrenheit to Celcius and Kalvin"; 
cout<< "\n 2. C for Celsius to Fahrenheit and Kalvin";
cout<< "\n 3. K for Kalvin to Fahrenheit and Celcius";
startagain:
cout<< "\n\n Please enter you choice: ";
cin >> ch;

switch(ch)
{ 
case 'f':
case 'F': 
cout<< " Please enter temprature in Farhenheit: ";
cin >> f_temp;
c_temp = (f_temp - 32) * 5/9;
k_temp = (f_temp + 459.67) * 5/9; 
cout<< " Celcius =" c_temp;
cout<< "\n Kelvin =" k_temp;
cout<< "\n Do you want to calculate another value (y/n): ";
cin >> quit;
if (quit == 'y' || quit == 'Y')
goto startagain;
break;

case 'c':
case 'C': 
cout<< " Please enter temprature in Celcius: ";
cin >> c_temp;
k_temp = c_temp + 273.15 ;
f_temp = c_temp * 9/5 + 32; 
cout<< " Kelvin =" k_temp;
cout<< "\n Farhenheit =" f_temp;
cout<< "\n Do you want to calculate another value (y/n): ";
cin >> quit;
if (quit == 'y' || quit == 'Y')
goto startagain;
break;

case 'k':
case 'K': 
cout<< " Please enter temprature in Kelvin: ";
cin >> k_temp;
c_temp = k_temp - 273.15 ;
f_temp = (k_temp - 273.14) * 9/5 + 32; 
cout<< " Celcius =" c_temp;
cout<< "\n Farhenheit =" f_temp;
cout<< "\n Do you want to calcute another value (y/n): ";
cin >> quit;
if (quit == 'y' || quit == 'Y')
goto startagain;
break;

default: 
cout<< "\n Invalid Choice"; 
}
cout<< endlendl;
system("pause"); 
}
Last edited on
hmdrdi wrote:
int main();

Lose the terminator (;). :-)
i did this but no result same errors
By indenting your code properly you will greatly increase the chance of seeing up the errors :

BTW, most of it are caused by missing << operator

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <cstdlib> // <-- for system()
using namespace std;

int main()
{
    double f_temp, k_temp, c_temp, temp;
    char ch, quit;
    
    cout<< " *********** Temprature Conversion Calculator **************";
    cout<< "\n\n Please enter the temprature unit for which you want the coverison ";
    cout<< "\n 1. F for Fahrenheit to Celcius and Kalvin"; 
    cout<< "\n 2. C for Celsius to Fahrenheit and Kalvin";
    cout<< "\n 3. K for Kalvin to Fahrenheit and Celcius";
    
    startagain:
    
    cout<< "\n\n Please enter you choice: ";
    cin >> ch;
    
    switch(ch)
    { 
        case 'f':
        case 'F': 
            cout<< " Please enter temprature in Farhenheit: ";
            cin >> f_temp;
            
            c_temp = (f_temp - 32) * 5/9;
            k_temp = (f_temp + 459.67) * 5/9;

            cout<< " Celcius =" << c_temp;
            cout<< "\n Kelvin =" << k_temp;
            
            cout<< "\n Do you want to calculate another value (y/n): ";
            cin >> quit;
            
            if (quit == 'y' || quit == 'Y')
                goto startagain;
            
            break;
    
        case 'c':
        case 'C': 
            cout<< " Please enter temprature in Celcius: ";
            cin >> c_temp;
            
            k_temp = c_temp + 273.15 ;
            f_temp = c_temp * 9/5 + 32; 
            
            cout<< " Kelvin =" << k_temp;
            cout<< "\n Farhenheit =" << f_temp;
            
            cout<< "\n Do you want to calculate another value (y/n): ";
            cin >> quit;
            
            if (quit == 'y' || quit == 'Y')
                goto startagain;
           
            break;
    
        case 'k':
        case 'K': 
            cout<< " Please enter temprature in Kelvin: ";
            cin >> k_temp;
            
            c_temp = k_temp - 273.15 ;
            f_temp = (k_temp - 273.14) * 9/5 + 32; 
            
            cout<< " Celcius =" << c_temp;
            cout<< "\n Farhenheit =" << f_temp;
            
            cout<< "\n Do you want to calcute another value (y/n): ";
            cin >> quit;
            
            if (quit == 'y' || quit == 'Y')
                goto startagain;
            
            break;
    
        default: 
            cout<< "\n Invalid Choice"; 
    }
    
    cout<< endl;
    
    system("pause"); 
}


http://www.learncpp.com/cpp-tutorial/16-whitespace-and-basic-formatting/
Last edited on
Where i missed the << operator. Can u tell me exact location plz?
compare it w/ my post above to see how you should use << operator

you're missing it in lines 24, 25, 38, 39, 52, and 53
Sorry but i am very confuse please can u write it for me??
ok, here is the working code, with comments on where you have errors :
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <cstdlib> // <-- you need this to use system();
using namespace std; // <-- you are missing this before

int main() // <-- you have an extra semicolon before
{
    double f_temp, k_temp, c_temp, temp;
    char ch, quit;
    
    cout<< " *********** Temprature Conversion Calculator **************";
    cout<< "\n\n Please enter the temprature unit for which you want the coverison ";
    cout<< "\n 1. F for Fahrenheit to Celcius and Kalvin"; 
    cout<< "\n 2. C for Celsius to Fahrenheit and Kalvin";
    cout<< "\n 3. K for Kalvin to Fahrenheit and Celcius";
    
    startagain:
    
    cout<< "\n\n Please enter you choice: ";
    cin >> ch;
    
    switch(ch)
    { 
        case 'f':
        case 'F': 
            cout<< " Please enter temprature in Farhenheit: ";
            cin >> f_temp;
            
            c_temp = (f_temp - 32) * 5/9;
            k_temp = (f_temp + 459.67) * 5/9;

            cout<< " Celcius =" << c_temp; // <--- you're missing << here
            cout<< "\n Kelvin =" << k_temp; // <-- you're missing << here
            
            cout<< "\n Do you want to calculate another value (y/n): ";
            cin >> quit;
            
            if (quit == 'y' || quit == 'Y')
                goto startagain;
            
            break;
    
        case 'c':
        case 'C': 
            cout<< " Please enter temprature in Celcius: ";
            cin >> c_temp;
            
            k_temp = c_temp + 273.15 ;
            f_temp = c_temp * 9/5 + 32; 
            
            cout<< " Kelvin =" << k_temp; // <-- missing << here
            cout<< "\n Farhenheit =" << f_temp; // <-- missing << here
            
            cout<< "\n Do you want to calculate another value (y/n): ";
            cin >> quit;
            
            if (quit == 'y' || quit == 'Y')
                goto startagain;
           
            break;
    
        case 'k':
        case 'K': 
            cout<< " Please enter temprature in Kelvin: ";
            cin >> k_temp;
            
            c_temp = k_temp - 273.15 ;
            f_temp = (k_temp - 273.14) * 9/5 + 32; 
            
            cout<< " Celcius =" << c_temp; // <-- here also
            cout<< "\n Farhenheit =" << f_temp; // <-- here also
            
            cout<< "\n Do you want to calcute another value (y/n): ";
            cin >> quit;
            
            if (quit == 'y' || quit == 'Y')
                goto startagain;
            
            break;
    
        default: 
            cout<< "\n Invalid Choice"; 
    }
    
    cout<< endl; // <-- in you previous code it's endlendl
    
    system("pause"); 
}
Last edited on
thanks a ton man. After reading your reply i just removed last extra endl and the program compiled successfully thanks again. :-)
Topic archived. No new replies allowed.