Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. void inputChecker(std::vector<std::string> names, std::string inputNames, int &exitLoop){
  6.     for(int i = 0; i < names.size(); i++){
  7.         if(names[i] == inputNames){
  8.             std::cout << "You've already input that name, program will exit!\n";
  9.             exitLoop = 1;
  10.         }
  11.     }
  12. }
  13.  
  14. int main(){
  15.    
  16.     std::string inputNames;
  17.     std::string inputScore;
  18.     std::vector<std::string> names;
  19.     std::vector<std::string> scores;
  20.    
  21.     int exitLoop = 0;
  22.    
  23.     std::string terminate = "No more";
  24.  
  25.     std::cout << "Enter name, then score. If you want to exit, input No more\n";   
  26.    
  27.     while(inputNames != terminate || exitLoop == 0){
  28.        
  29.         //input of names
  30.         std::cout << "Enter name: ";
  31.         getline(std::cin, inputNames);
  32.        
  33.         //exit of input if No more entered
  34.         if(inputNames == terminate){
  35.             break;
  36.             exitLoop = 1;
  37.         }
  38.        
  39.         //Loop breaks if name entered twice
  40.         inputChecker(names, inputNames, exitLoop);
  41.         if(exitLoop == 1)
  42.             break;
  43.        
  44.         names.push_back(inputNames);
  45.                
  46.         //input of scores
  47.         std::cout << "Enter score: ";
  48.         getline(std::cin, inputScore); 
  49.         scores.push_back(inputScore);
  50.         std::cout << "\n";
  51.        
  52.     }
  53.  
  54.     //Input search type (Name or score or nothing)
  55.     std::string searchChoice;
  56.     std::cout << "If you want to search by name, type Name, if you want to search by score, enter score, if you don't want to search, enter nothing\n";
  57.     getline(std::cin, searchChoice);
  58.  
  59.     std::string search;
  60.     std::string searchScore;
  61.    
  62.     int notFound = 0;
  63.    
  64.     //Search by name
  65.     if(searchChoice == "Name" || searchChoice == "name" || searchChoice == "NAME"){
  66.         std::cout << "Enter name: \n";
  67.         std::cin >> search;
  68.        
  69.         for(int i = 0; i <= names.size() - 1 ; i++){
  70.             if(names[i] == search){
  71.                 std::cout << "Here is your search result: \n";
  72.                 std::cout << names[i] << " " << scores[i] << "\n";
  73.             }
  74.         }          
  75.     }
  76.    
  77.     //Search by score
  78.     else if(searchChoice == "Score" || searchChoice == "score" || searchChoice == "SCORE"){
  79.         std::cout << "Enter score: \n";
  80.         std::cin >> searchScore;
  81.        
  82.         std::cout << "Your result: \n";
  83.         for(int i = 0; i < scores.size(); i++){
  84.             if(scores[i] == searchScore){
  85.                 std::cout << names[i] << " " << scores[i] << "\n";
  86.             }
  87.             else
  88.                 notFound = 1;
  89.         }
  90.         if(notFound == 1)
  91.             std::cout << "Score not found";
  92.     }
  93.    
  94.     //Stop
  95.     else if(searchChoice == "Nothing" || searchChoice == "nothing" || searchInfo == "NOTHING"){
  96.     }
  97.    
  98.     //Error
  99.     else
  100.         std::cout << "You entered your character wrong.";
  101.        
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement