如何在while循环中使用多个语句?

时间:2015-11-12 14:59:37

标签: c++ while-loop

#include<iostream>

using namespace std;
main()    

{   
    int em;
    char name,add;

    cout<<"\n enter number of employees : ";
    cin>>em;
    // here we took an input by the name employee...

    while(em<=9)      //using while loop

员工编号存储在em中并放入循环中... 为了放置多个响应,我在代码块中放了两个输入关键字......但是它没有正常工作。

    {
        cout<<"\n enter name: ";      //code block 
        cin>>name;
        cout<<"\n enter address : ";
        cin>>add;

        em=em+1;

    }
    return 0;
}

1 个答案:

答案 0 :(得分:2)

问题在于你的char name,add;声明它应该是char name[100],add[100];或(更现代,更安全的C ++)std::string name,add;。在后一种情况下,您还需要#include <string>