黄金点游戏程序

 


1
#include"iostream" 2 #include"windows.h" 3 #include"string" 4 #include"map" 5 using namespace std; 6 int main() 7 { 8 int check = 1; 9 while (check == 1) 10 { 11 int people = 0; 12 double ave = 0.0; 13 int max = 0; 14 map<int, string>mapStudent; 15 pair< std::map< int, string >::iterator, bool > ret; 16 cout << "请输入黄金点游戏的范围:" << endl; 17 cin >> max; 18 cout << "请输入游戏人数:" << endl; 19 cin >> people; 20 for (int i = 0; i < people; i++) 21 { 22 23 int ch; 24 string name; 25 cout << "黄金点的范围:" << max << endl << "请输入你的点数:" << endl; 26 cin >> ch; 27 if (ch>max || ch<0) 28 { 29 cout << "输入的数范围错误,请重新输入:" << endl; 30 cout << "黄金点的范围:" << max << endl << "请输入你的点数:" << endl; 31 cin >> ch; 32 } 33 cout << "请输入你的姓名:" << endl; 34 cin >> name; 35 ret = mapStudent.insert(pair<int, string>(ch, name)); 36 if (ret.second){ 37 std::cout << "输入成功:" << std::endl; 38 Sleep(500); 39 system("cls"); 40 } 41 else{ 42 std::cout << "输入的数重复,请重新输入" << std::endl; 43 people++; 44 Sleep(500); 45 system("cls"); 46 } 47 } 48 map<int, string>::iterator iter; 49 for (iter = mapStudent.begin(); iter != mapStudent.end(); iter++) 50 { 51 ave += iter->first; 52 } 53 ave = (ave / 3.0)*0.618; 54 cout << "\t黄金点数" << " " << "\t差值(输入的数与平均数的差)" << " " << "\t姓名" << endl; 55 for (iter = mapStudent.begin(); iter != mapStudent.end(); iter++) 56 { 57 double n = 0.0; 58 n = abs(iter->first - ave); 59 cout << "\t" << ave << " " << "\t\t" << n << " " << "\t\t\t\t" << iter->second << endl; 60 } 61 cout << "继续游戏请按1,退出游戏请按其他键!" << endl; 62 cin >> check; 63 } 64 system("pause"); 65 return 0; 66 }
运行环境:windows ,linux 命令行
语言:C++

 

posted @ 2017-10-09 21:03  spring_c  阅读(220)  评论(0编辑  收藏  举报