Error: Operand types are incompatible, char & constant char

Hello all,

As the title states, I have a problem where all the comparison operators are generating an error. The assignment explicitly states that no arguments are passed to the function. What should I do here on out? Any help would be appreciated. Thank you.


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
//Attached: HW_1a
//=======================
//Project: HW_1a.cpp
//=======================
//Programmer: Dave 
//Class: CMPR 131
//=======================

#include<iostream>
#include<iomanip> 
#include <string> 

using namespace std;

void getCities(string (&cities)[5]);
char getChoice();
void displayInOrder();
void displayInReverse();

int main()
{
	string cities[5];
	char choice;
	getCities(cities);
	choice = getChoice();

	if (choice == "O" || choice == "o") 
	{
		displayInOrder(); 
	}
	else if (choice == "R" || choice == "r") 
	{
		(displayInReverse());
	}
	else 
	{
		cout << "Invalid entry - Must be O or R!" << endl;
	}
}

void getCities(string (&cities)[5])
{
	for (int i = 0; i < 5; i++)
	{
		cout << "Enter in a city name: " << endl;
		cin >> cities[i];
	}
}

char getChoice()
{
	char choice;

	cout << "How do you want to see the cities displayed?" << endl;
	cout << "Enter O for In Order, or R for In Reverse (R):" << endl;
	cin >> choice;

	return choice;
}

void displayInOrder(string (&cities)[5])
{
	for (int i = 0; i < 5; i++)
	{
		cout << cities[i] << endl;
	}
}

void displayInReverse(string (&cities)[5])
{
	for (int i = 4; i >= 0; i--)
	{
		cout << cities[i] << endl;
	}
}
Last edited on
Do you know the difference between a string "literal" and a char 'literal'?

No
A string literal is surrounded by double quotes "string literal", a single char constant is surrounded by single quotes 'D'.

Your if() statement is using string literals instead of char literals.

Brilliant. Thank you for the explanation. Do you happen to know what an unresolved external is?
It usually means that the linker can't find a function with the proper signature. Make sure your function prototype, function implementation and function call all agree as to the number and types of parameters.

By the way the error messages usually will tell you exactly what the problem was so in future post the complete error messages, all of them exactly as they appear in your development environment. Then perhaps someone can help you decipher the error messages. And note that one error may generate multiple messages, which can help pinpoint the actual problems.


Topic archived. No new replies allowed.