如何在内部使用while循环

How to use while loop for multiple statements inside?

本文关键字:while 循环 在内部      更新时间:2023-10-16
#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;
}

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