Need help with Errors on line 58

for line 58 i am getting the following errors.
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

Error 2 IntelliSense: no operator "<<" matches these operands
operand types are: std::ostream << std::string

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  This program will ask the user for the  number of accidents for that year.
It will then use two functions to calculate the area with the lowest
accidents and displays the name of the area and the number of accidents.
*/

#include <iostream>
#include <cstring>

using namespace std;

//Function prototype
int numAccident(string regionName);
void findLowest(int north, int south, int east,  int west, int central);

string regionName;

int main()
{
// Variables.
	char again;        // Using charcaters.
	int north, south, east, west, central;
	do
	{
		cout << "Accidents for the North Region: ";
		north = numAccident(regionName);
		
		cout << "Accindents for the South Region: ";
		south = numAccident(regionName);
		
		cout << "Accidents for the East Region: ";
		east = numAccident(regionName);
	
		cout << "Accidents for the West Region: ";
		west = numAccident(regionName);

		cout << "Accidents for the Central Region: ";
		central = numAccident(regionName);

		// Aks user if they would like try again.
		cout << "Would you like to try again? (y or n)";
		cin >> again;
	} while (again == 'y' || again == 'Y');

	system("pause");
	return 0;
	}

/********************************************************************
*                   numAccidents Function                           *
* This function is passed the name of the region. Its asks the user *
* for the number of traffic accidents reported in that region during*
* the lst year, validates the input, then returns it                *
* ******************************************************************/
int numAccident(string regionName)
{
	int accident;
	
	cout << regionName << "Accidents: ";
	cin >> accident;

	if (accident < 0)
	{
		cout << "You cannot have less than zero accidents.\n";
	}
	else
		return accident;
}

/************************************************************************
*                    void findLowest Function                           *
* This function is passed the five accident totals.It will determine    *
* which is the smallest and prints the name of the region, along with   *
* its accident figure.                                                  *
************************************************************************/
void findLowest(int north, int south, int east, int west, int central)
{
	if (north < south && south < east && east < west && west < central)
		cout << "The Central Region came in the lowest with " << central << " accidents." << endl;

	else if (south < north && north < east && east < central && central < west)
		cout << "The west Region came in the lowest with " << west << " accidents." << endl;

	else if (central < south && south < north && north < west && west < east)
		cout << "The East Region came in with the lowest with " << east << " accidents." << endl;

	else if (east < north && north < west && west < central && central < south)
		cout << "The South Region came in the lowset with " << south << "accidents." << endl;

	else
		cout << "The North Region came in the lowest with" << north << " accidents." << endl;

}
Change #include <cstring> to #include <string> .
I changed that and it now compiles. But mu out put it wrong and I have an error:
Warning 1 warning C4715: 'numAccident' : not all control paths return a value

it is located somewhere in the numAccident function.

Also for some reason I am not getting the correct answer even though it looks correct.
Warning 1 warning C4715: 'numAccident' : not all control paths return a value


If they enter < 0 for accidents, you output an error message but don't return a value from the function. You could prompt them to re-enter, or maybe just return a value of 0.


Edit: Check the logic in the findLowest function.
Line 77 would imply that central is the highest number. But you output that it's the lowest.
Last edited on
This function is done the correct way, I think, it still doesn't work correctly.
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
/************************************************************************
*                    void findLowest Function                           *
* This function is passed the five accident totals.It will determine    *
* which is the smallest and prints the name of the region, along with   *
* its accident figure.                                                  *
************************************************************************/
void findLowest(int north, int south, int east, int west, int central)
{
	if (north < south && south < east && east < west && west < central)
	{
		cout << "The Central Region came in the lowest with " << north << " accidents." << endl;
		cout << endl;
	}
	else if (south < north && north < east && east < west && west < central)
	{
		cout << "The west Region came in the lowest with " << south << " accidents." << endl;
		cout << endl;
	}
	else if (east < north && north < south && south < west && west < central)
	{
		cout << "The East Region came in with the lowest with " << east << " accidents." << endl;
		cout << endl;
	}
	else if (west < north && north < south && south < east && east < central)
	{
		cout << "The South Region came in the lowset with " << west << " accidents." << endl;
		cout << endl;
	}
	else
		cout << "The North Region came in the lowest with" << central << " accidents." << endl;

	
}
Last edited on
Your if statements are defective. e.g. Line 9: What does the relationship between south and east have to do with the cout statement on line 11?

Line 11: Which are you trying to display? You state "Central region", but you display the count for north.

Shouldn't this be:
1
2
3
4
if (north < south && north < east && north < west && north < central)
    {    cout << "The North Region came in the lowest with " << north << " accidents." << endl;
        cout << endl;
    }

etc... for each of the other regions.

What happens if two regions are tied for lowest?
Last edited on
Topic archived. No new replies allowed.