Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- void inputChecker(std::vector<std::string> names, std::string inputNames, int &exitLoop){
- for(int i = 0; i < names.size(); i++){
- if(names[i] == inputNames){
- std::cout << "You've already input that name, program will exit!\n";
- exitLoop = 1;
- }
- }
- }
- int main(){
- std::string inputNames;
- std::string inputScore;
- std::vector<std::string> names;
- std::vector<std::string> scores;
- int exitLoop = 0;
- std::string terminate = "No more";
- std::cout << "Enter name, then score. If you want to exit, input No more\n";
- while(inputNames != terminate || exitLoop == 0){
- //input of names
- std::cout << "Enter name: ";
- getline(std::cin, inputNames);
- //exit of input if No more entered
- if(inputNames == terminate){
- break;
- exitLoop = 1;
- }
- //Loop breaks if name entered twice
- inputChecker(names, inputNames, exitLoop);
- if(exitLoop == 1)
- break;
- names.push_back(inputNames);
- //input of scores
- std::cout << "Enter score: ";
- getline(std::cin, inputScore);
- scores.push_back(inputScore);
- std::cout << "\n";
- }
- //Input search type (Name or score or nothing)
- std::string searchChoice;
- 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";
- getline(std::cin, searchChoice);
- std::string search;
- std::string searchScore;
- int notFound = 0;
- //Search by name
- if(searchChoice == "Name" || searchChoice == "name" || searchChoice == "NAME"){
- std::cout << "Enter name: \n";
- std::cin >> search;
- for(int i = 0; i <= names.size() - 1 ; i++){
- if(names[i] == search){
- std::cout << "Here is your search result: \n";
- std::cout << names[i] << " " << scores[i] << "\n";
- }
- }
- }
- //Search by score
- else if(searchChoice == "Score" || searchChoice == "score" || searchChoice == "SCORE"){
- std::cout << "Enter score: \n";
- std::cin >> searchScore;
- std::cout << "Your result: \n";
- for(int i = 0; i < scores.size(); i++){
- if(scores[i] == searchScore){
- std::cout << names[i] << " " << scores[i] << "\n";
- }
- else
- notFound = 1;
- }
- if(notFound == 1)
- std::cout << "Score not found";
- }
- //Stop
- else if(searchChoice == "Nothing" || searchChoice == "nothing" || searchInfo == "NOTHING"){
- }
- //Error
- else
- std::cout << "You entered your character wrong.";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement