Strings

I have to make a program that asks the user for 4 cities and then asks them if they want to display the 4 cities in the order they were typed in or in the reverse order. We have to have a getCities() function, a getChoice() function, and a displayInOrder() function.

getCities has to get the four city names from the user.
getChoice has to get whether or not to display in order or reverse.
displayInOrder is the display function.

We also have to put the option of letting the user do the program again.

This is the code I have so far.

When I check the output it gives me nothing so please take a look at it and get back to me.

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

int main()
{
	string getCities(int CITIES, string city[]);
	char getChoice(char choice);
	system("pause");
	return 0;
}

string getCities(int CITIES, string city[])
{
	for (int i = 0; i < CITIES; i++)
	{                
		int j = 0;
		j = i + 1;
		cout << "Enter city number " << j << ".\n";
		getline(cin, city[i]);
	}
	return 0;
}

char getChoice(char choice)
{

	string getCities(int CITIES, string city[]);
	string city[4];
	cin >> choice;
	if (choice == 'o' || choice =='O')
	{
		cout << city[0] << ", " << city[1] << ", " << city[2] << ", " << city[3] << ".\n" ;
	}
	else if (choice == 'r' || choice == 'R')
	{
		cout << city[4] << ", " << city[3] << ", " << city[2] << ", " << city[1] << ".\n" ;
	}
	else 
	{
		cout << "You have put in a wrong input please try again.";
	}
	return 0;
}


Last edited on
Topic archived. No new replies allowed.