Need help finding the syntax (parse) error


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
//temp_conversion.cpp


#include <iostream.h>
#include <conio.h>
#include <iomanip.h>

int main()

{

int fah, cal;
char type, ans; //type of conversion & ans. to continue/terminate
float degree; //degree of temp(s)
ans='y';
fah=(9.0/5*degree+32);
cel=(5.0/9*(degree-32);

while (ans=='y')
{
cout<<"\nPress C to convert to Celsius, F to conver to Fahrenhiet: ";
cin>>type;

if (type=='F' | 'f')
{
cout<<"\nType in the temperature: ";
cin>>degree;
cout<<"\n"<<degrees<<" degrees Celsius converted to Fahrenhiet is: "<< fixed << setprecision(1)<<fah<<endl;
}

else if (type=='C' | 'c')
{
cout<<"\nType in the temperature: ";
cin>>degree;
cout<<"\n"<<degrees<<" degrees Fahrenhiet converted to Celsius is: " << fixed << setprecision(1)<<cel<<endl;
}
else
{
cout<<"\nInvalid conversion entry!"<<endl;
}

getch();
cout<<"\n\nWould you like to continue? (y/n): ";
cin>>ans;

if (ans=='y' || 'Y')
{
(ans=='y');
}
else if (ans=='n' || 'N')
{
cout<<"Thank you for using the Temperature Converter!"<<endl;
}
}

return 0;

}
Last edited on
What parse error? Those error messages do contain useful information.

Does it perhaps mention a use of unknown identifier? The type of degree is float, but what is a degrees?


PS. the values of fah and cel are undefined.
Yeah, undefined symbol 'degrees' in function main().

What do I make degrees then? Would I initalize it to 0, as I'm inputing as the program goes on?

When I tried defining fah, and cel, it gave me an error.
Your intention seems to be to ask for a temperature and then to show it (and a conversion).
However, you ask for a value and store it in 'degree', but then try to show the value of 'degrees'?

You cannot compute the value of variables 'fah' or 'cel' before you have received 'degree' from the user. You could define functions that take a value and returns a converted value, and call these functions.
When asking for help with error messgaes, PLEASE INCLUDE THE ERROR MESSAGE in it's entirity.

Lines 4,6: Correct header file names are <iostream> and <iomanip>. C++ headers do not use the .h suffix.
Line 7: You're missing using namespace std;
Line 12: You misspelled cel as cal. This causes cel to be undefined.
Lines 16,17: You're using degree in calculations, but you haven't initialized it.
Line 17: You have unmatched parentheses.
Lines 24,31,46,50: You can't write a comparison wth an implicit left hand side. You need to write it as follows:
 
if (type=='F' || type=='f')

Lines 24,31: You're using bitwise or (|), not logical or (||).
Line 28: You used degrees which doesn't exist. The variable defined is named degree.
Line 48: That statement does nothing. It's a comparison and the result of the comparison is ignored. Did you mean assignment? ans='y');












Topic archived. No new replies allowed.