incompatible types in assignment of 'bool' to 'char[4]'

Help!! I'm doing this program on temp. conversion and I encountered the error 'incompatible types in assignment of 'bool' to 'char[4]' Please help ASAP!

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

int main()
{
    float celsius, fahrenheit, value;
    char unit[4] {'c', 'C', 'f', 'F'};

    system("cls");

    cout << "Temperature Conversion ( C <--> F)\n";
    cout << "-------------------------------------------\n";
    cout << endl;
    cout << endl;

    cout << "Input the temperature value: \n";
    cin >> value;
    cout << endl;
    cout << "Unit of measure [c/f]: \n";
    cin >> unit;

    if (unit = 'c' || 'C') {
            fahrenheit = (value * 0.9) / 5.0 + 32;
             cout << "F" << fahrenheit << endl;
             } else{
             celsius = (value - 32) * 5/9;
             cout << "C" << celsius << endl;
             }

    cout << endl;
    cin.get();
    return 0;
}
you are attempting to assign unit to c on line 23.

unit is an array. did you mean unit[0] or unit[variable] ?
= is assignment. did you mean == there as well?
comparisons in c++ are explicit, not human. you must say
if(unit[0] == 'c' || unit[0] == 'C')


that said your code needs help.
make unit a char, and lose the initialization and array stuff on unit?
eg
char unit;
..
cin >> unit;
if(unit == 'c' || unit == 'C') //this is ok now, its no longer an array

Last edited on
Topic archived. No new replies allowed.