zoukankan      html  css  js  c++  java
  • C艹重复输入小方法,for循环+while

    #include <iostream>
    #include <cctype>
    #include <string>
    
    const int Max = 5;
    
    int main(int argc, char const *argv[]) {
    
      using namespace std;
    
      int golf[Max];
      int i;
      for (i = 0; i < Max; i++) {
        std::cout << "round #" << i+1 << '
    ';
        while (!(cin >> golf[i])) {
          cin.clear();
          cin.get();
          // while (cin.get() != '
    ') {
          //   continue;
          // }
          std::cout << "please enter a number:" << '
    ';
        }
      }
      double total = 0.0;
      for (i = 0;i < Max; i++) {
        total += golf[i];
      }
      std::cout << total << '
    ';
    
    
      return 0;
    }
    int vector_begin(){
        vector<string> words;
        string str;
        cout << "please input you content==>:" << '
    ';
        while (cin >> str){
            words.push_back(str);
            if (cin.get() == '
    '){
                break;
            }
        }
    
        vector<string>::iterator iter;
    
        for (iter =words.begin(); iter != words.end(); iter++){
            cout << *iter << '
    ';
        }
    
        return 0;
    }
    
    
    int main () {
    //    assign();
    
        vector_begin();
        return 0;
    }
  • 相关阅读:
    Markdown学习笔记
    Go 学习笔记(一)
    case中定义变量
    <转>MySql 与Oracle区别
    Java 时间转换问题总结
    线程之间共享
    并发编程快速入门
    redis主从复制
    jedis操作redis
    redis持久化方案
  • 原文地址:https://www.cnblogs.com/renfanzi/p/7474188.html
Copyright © 2011-2022 走看看