初学c++,这个程序要怎样才能实现?

来源:百度知道 编辑:UC知道 时间:2024/05/22 04:53:16
我用的是vc6.0
就是输入一个名字给出相应的一段评价,不同的名字有不同的评价,没有的名字提示说"你输入的名字有误"
四楼的大哥,照你的方法怎么只有"This name is not available"这一句哈?

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {

map<string, string> describ;
describ["Name A"] = "Good";
describ["Name B"] = "Bad";
describ["Name C"] = "Otherwise";

string name;

while(cin >> name){
if(0 == describ.count(name)){
cout << "This name is not available" << endl;
continue;
}
cout << "The describe of " << name << " is " << describ[name] << endl;

}

}

用判断语句

这个很简单的,用switch语句就可以了

用条件句:
if
else if
else if
else if
……