삭제가 안돼서 수정했삼 ㅋ
출발역과 도착역을 입력하면 그에 맞게 가격을 출력해주는 간단한 프로그램입니다! 단, 출발역과 도착역은 제가 글로벌 변수로 지정한 station배열에 적힌 역들 중 하나여야만 합니다! 만약, "미아"를 입력하면 없는 역이라고 말해줘야 합니다.
#include <iostream>
#include <string>
using namespace std;
string station[11] = { "신림", "봉천", "사당", "방배", "서초", "교대", "강남", "역삼", "선릉", "삼성", "잠실" };
int station_cmp(string input){
for (int i = 0; i < 11; i++){
if (input.compare(station[i]) == 0){
return 0;
}
else if (input.compare(station[i]) == 1){
cout << " * 없는 역입니다. 다시 입력해 주세요." << endl;
return 1;
}
}
}
int main(){
string start, end;
cout << "==========================" << endl;
cout << " 지하철 요금 계산" << endl;
cout << "==========================" << endl;
cout << "" << endl;
while (1){
cout << " 출발역 : ";
cin >> start;
station_cmp(start);
}
while (1){
cout << " 도착역 : ";
cin >> end;
station_cmp(end);
}
}
입력받은 출발역, 도착역을 station_cmp에서 받고 비교를 하는데 어째서인지 사당 서초 잠실 등의 역들이 없는 역이라고 뜹니다! 혹시 함수에 문제가 있는 걸까요 ㅠㅠㅠ?! 조언 부탁드립니다..!
출발역과 도착역을 입력하면 그에 맞게 가격을 출력해주는 간단한 프로그램입니다! 단, 출발역과 도착역은 제가 글로벌 변수로 지정한 station배열에 적힌 역들 중 하나여야만 합니다! 만약, "미아"를 입력하면 없는 역이라고 말해줘야 합니다.
using namespace std;
string station[11] = { "신림", "봉천", "사당", "방배", "서초", "교대", "강남", "역삼", "선릉", "삼성", "잠실" };
int station_cmp(string input){
for (int i = 0; i < 11; i++){
if (input.compare(station[i]) == 0){
return 0;
}
else if (input.compare(station[i]) == 1){
cout << " * 없는 역입니다. 다시 입력해 주세요." << endl;
return 1;
}
}
}
int main(){ string start, end; cout << "==========================" << endl; cout << " 지하철 요금 계산" << endl; cout << "==========================" << endl; cout << "" << endl;
while (1){
cout << " 출발역 : ";
cin >> start;
station_cmp(start);
}
while (1){
cout << " 도착역 : ";
cin >> end;
station_cmp(end);
}
}
입력받은 출발역, 도착역을 station_cmp에서 받고 비교를 하는데 어째서인지 사당 서초 잠실 등의 역들이 없는 역이라고 뜹니다! 혹시 함수에 문제가 있는 걸까요 ㅠㅠㅠ?! 조언 부탁드립니다..!