comparing strings issue

I'm having a problem with the two if statements. I get the error no match for 'operator>'. I'm doing it exactly like my c++ book says for comparing two strings. The code works fine up until that part. I need to change the temp type from F to C, if it is F.
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
    string time_stamp[num_of_readings];
    string temperature[num_of_readings];
    string temp_type[num_of_readings];
    string str_year[num_of_readings], str_month[num_of_readings];
    string str_day[num_of_readings], str_time[num_of_readings];  
    string str_TempType[num_of_readings], str_Temp[num_of_readings]; 
    string str_cmpr1[1] = "C";
    string str_cmpr2[1] = "c";
    
    
    cout << "Number of Readings: " << num_of_readings << endl;
    cout << endl;
    
    for(int i = 0; i < num_of_readings; i++)
    {
             inFile >> time_stamp[i] >> temperature[i];
             
             
             str_year[i] = time_stamp[i].substr (0,4); 
             str_month[i] = time_stamp[i].substr (4,2); 
             str_day[i] = time_stamp[i].substr (6,2); 
             str_time[i] = time_stamp[i].substr (8,4); 
             str_TempType[i] = temperature[i].substr (0,1);
             str_Temp[i] = temperature[i].substr (1,5); 
             
             
             if ((str_TempType[i] > str_cmpr1) && (str_TempType[i] < str_cmpr2))
                {
                        str_Temp[i] = (str_Temp[i]-32)*(5/9);
                        str_TempType[i] = 'C';
                }   
             else if ((str_TempType[i] > str_cmpr1) && (str_TempType[i] > str_cmpr2))
                {
                        str_Temp[i] = (str_Temp[i]-32)*(5/9);
                        str_TempType[i] = 'C';   
                }     

Post the compiler error.
1
2
string str_cmpr1[1]; //strcmpr1 is an array of only one element (?)
str_TempType[i] > str_cmpr1 //trying to compare a string against an array 
o ok ya i totally didnt catch that. i think that might the fix its not supposed to be an array just a string to compare it against
ok so i changed it to just a string and i got this error

no match for 'operator-' in 'str_Temp[i] - 32'

line 29 in the code is the formula for changing str_Temp from celsius to ahrenheit
1
2
3
string str_Temp[num_of_readings]; //an array of strings
str_Temp[i] //it's a string
str_Temp[i]-32 //that makes no sense "hello"-32 ? 

You should change the type of your variables to float.
Also, because of integer arithmetic, 5/9 = 0
so is there a way to get the last 4 places of the string temperature into a float?
http://www.cplusplus.com/articles/numb_to_text/#s2n
But why do you need it as a string in the first place?
if the temp is in Fahrenheit it needs to be converted to celsius. I dont know how to test if its and F or a C and then change the data accordingly
1
2
3
4
5
6
7
8
double value;
char suffix;
cin >> value >> suffix; //input 3.14F or 3.14 F
switch( suffix ){
case 'F': case 'f': cout <<value<< " Fahrenheit"<<endl; break;
case 'C': case 'c': cout <<value<< " Celsius"<<endl; break;
default: cout << "Invalid input"<<endl;
}
Last edited on
Well i figured it out, finally. the switch statements helped alot. I appreciate all the help ne555 thank you very much.
Topic archived. No new replies allowed.