dummy code
Code:
int main()
{
char where [30]; // if char is one char it is an int value you can use
// for a switch.
cout << " where ya want a go?";
cin >> where;
// maybe even have a means to print out a list of available places to go to.
// then user can pick one.
// needs to be an int here
//the only thing needed is a means to connect the two together,
// input against data
// enum
// for easier comparison
switch ( where )
{
// std::string bar = "CHD";
case 'c':
std::cout << "YOUR TICKET CHARGE IS Rs5/. \n";
break;
std::string bar1 = "KSH";
std::string bar2 = "CL";
std::string bar3 = "VS";
std::string bar4 = "VIS";
std::string bar5 = "GTB";
std::string bar6 = "MT";
std::string bar7 = "AZ";
cin >> IP1;
return 0;
}
so I would scrap that idea and I'd go to enum.
Code:
#include<iostream>
#include<vector>
#include<cstring>
#include<fstream>
using namespace std;
int main()
{
int where;
vector <string> space_list;
string word;
ifstream fillfile("string_vector_data", ios::in);
if (!fillfile)
{
cerr << "Can't open input file " << endl;
exit(1);
}
while(!fillfile.eof())
{
fillfile >> word;
space_list.push_back(word);
}
fillfile.close();
for (unsigned int n=0; n<space_list.size(); ++n)
cout << n << ": "<< space_list.at( n ) << endl;
cout << "pick a number where ya want a go?";
cin >> where;
switch (where)
{
case 0:
std::cout << "YOUR TICKET CHARGE IS Rs10/. \n";
break;
case 1:
std::cout << "YOUR TICKET CHARGE IS Rs20/. \n";
break;
default:
break;
}
return 0;
}
I scraped that enum idea too, really fast. building off
what I already had got me this output.
Code:
userx@slackwhere:~/bin
$ ./enummy_prices
0: CHD
1: KSH
2: CL
3: VS
4: VIS
5: GTB
6: MT
7: AZ
8: AN
9: JH
pick a number where ya want a go?0
YOUR TICKET CHARGE IS Rs10/.
that is the benefits of an array as well.
I'd figure out a formatting method to print that really long list in columns, left to right. So it will not print out in its entire length making it easier to read.