I can't seem to understand what the error code is

Hello all! C++ noob here!

I took part 1 of C++ back in 2006, and I'm suffering from CRS(Can't remember shit). I passed the class with C, average, I guess a good grade for C++.
Never took part 2.
Now, after 7 years, I want to get my feet wet again.
Started doing basic stuff, have a book (Adams & Nyhoff C++: An Introduction to Computing [3rd Edition]), and a couple of PDFs, including C++ for dummies.

So I was able to do a couple of area, radius, etc..for triangle and circles and squares...I did the Fahr to Cels, and a separate code for C to F.
I guess I was thinking "I'm a big boy now", and wanted to jump in the deep end of the pool, adding Kelvin, and doing it in a if-else statement.
The thing is:
That in my logic, I guess I'm doing it correctly, HOWEVER, the compiler, Dev C++ V. 5.4.2, for Windows, is giving me an error, a simple error, of a semi-colon.
(Line 51 column 6 C:\Users\Administrator\Desktop\ProgramasCPP\CPP Programs\Celsius-Kelvin-Fahrenheit.cpp [Error] stray '\327' in program
C:\Users\Administrator\Desktop\ProgramasCPP\CPP Programs\Celsius-Kelvin-Fahrenheit.cpp In function 'int main()':Line 51 column 20 C:\Users\Administrator\Desktop\ProgramasCPP\CPP Programs\Celsius-Kelvin-Fahrenheit.cpp [Error] expected ';' before numeric constant)
and FOR THE LIFE OF ME, I cannot understand WHY, since it has a semicolon.
I will post the code, for you to see.
Don't worry about the cout(s), they are in Spanish, but the code is in English.

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
 /*Programa para calcular temperaturas entre Celsius, Fahrenheit y Kelvin, utilizando if else. */

#include <iostream>


using namespace std;

int main()
{
	float TempC, TempF, TempK;
	
		cout << "Programa para convertir distintas escalas de temperaturas\n";
		cout << "Por favor indique cual temperatura desea convertir,\n";
		cout << "y el sistema hara 2 conversiones.";
		cout << "\nElija 1, para Celsius:\n";
		cout << "Elija 2, para Fahrenheit:\n";
		cout << "Elija 3, para Kelvin: \n";
	
		char select;
		cin >> select;
		
			if (select==1)
				{
					cout << "Usted ha seleccionado convertir una temperatura Celsius.\n";
					cout << "Entre la temperatura Celsius, y el sistema devolvera Fahrenheit y Kelvin.\n";
					cin >> TempC;
					TempK = TempC + 273.15;
					TempF = (1.8 * TempC) +32;
					cout << "La conversion de " << TempC << "° a grados Fahrenheit es: " << TempF << "grados.\n";
					cout << "La conversion de " << TempC << "° a grados Kelvin: " << TempK << "grados.\n";
				}
				
		
			else if (select==2)
  				{	
				  	
    				cout << "Usted ha seleccionado convertir una temperatura Fahrenheit.\n";
					cout << "Entre la temperatura Fahrenheit, y el sistema devolvera Celsius y Kelvin.\n";
					cin >> TempF;
					TempC = (TempF-32) /1.8;
					TempK = (TempF+459.67) /1.8;
					cout << "La conversion de " << TempF << "° a grados Celsius es: " << TempC << "grados.\n";
					cout << "La conversion de " << TempF << "° a grados Kelvin: " << TempK << "grados.\n";
  				}
		
			else
 				 {
    				cout << "Usted ha seleccionado convertir una temperatura Kelvin.\n";
					cout << "Entre la temperatura Kelvin, y el sistema devolvera Celsius y Kelvin.\n";
					cin >> TempK;
					TempF = TempK×1.8-459.67; //The error code is here, in line 51
					TempC = TempK-273.15;
					cout << "La conversion de " << TempK << "° a grados Fahrenheit es: " << TempF << "grados.\n";
					cout << "La conversion de " << TempK << "° a grados Celsius: " << TempC << "grados.\n";
  				}		
	
		return 0;
}


Thank you all!
Change line 51 with this:

 
TempF = TempK * 1.8 - 459.67;


Not x but *
Thank you ar2007.
I will let you know what happens.
ar2007:
I was able to compile it, no problems...I can't believe I didn't notice the ASCII code for ×.
Anyway: Now I'm having a logical error.
Though the program compiles perfectly, it sends me to the Kelvin selection, only.
Bypasses Celsius and Fahrenheit.
Now, I understand, maybe it's easier to make the program run using case switch, however, my newbie knowledge hasn't allowed me to get there yet.
Isn't it possible to do this program with if else statements??

Thanks, all!!
Last edited on
You are taking your input as a char:

1
2
3
4
char select;
cin >> select;
		
    if (select==1)


A 'char' is a character. So if the player inputs a space, then your select var will contain a space (select == ' '), or if they input the letter J, then it will be the letter J (select == 'J').

You are taking a character and comparing it to an integer, which is a different type. C++ allows this comparison because characters are integers, but the code doesn't do what you expect.

If 'select' is a char, then you need to compare against the character version of 1, 2, etc:

 
if(select == '1') // <- note the 1 is in single quotes, making it a character, not an integer 


Technically 'select' actually contains the ASCII code for whatever character it represents. The ASCII code for the character '1' is much higher than the actual integral value of 1.



EDIT:

OR, instead of using '1', '2', etc... you could change select to be an int. In which case when the user inputs the integral value of 1 you can compare it to 1 without any problem.
Last edited on
Disch:
I wasn't sure about that...but it makes sense.
I shall try it again, and let you know how it came out.
Thanks!
Disch:
I left the code how I had it, and placed the single quotes, before and after the numbers, totally works!!!
Thank you all.
Problem solved!!!
Topic archived. No new replies allowed.