what should i do so the user can enter their own data

时间:2016-11-21 15:36:32

标签: c++

Create a c++ program which accepts an employee’s full name, hours worked, and pay grade, and displays the employee’s name, and salary. The following data should be stored in parallel arrays.

#include <iostream>

using namespace std;

int main(void)

{
    string firstnamearr[10] = {" "," "," "," "," "," "," "," "," "," "};
    string lastnamearr[10] = {" "," "," "," "," "," "," "," "," "," "};
    int paygrade[10] = {};
    int hoursworked[10] = {};
    int salary[10] = {};

    cout << "\n The Names,Paygrade,Hoursworked and Salary of employees:";
    cout << "\n -------------------------------------------------------";
    cout << "\n firstname\tlastname\tpaygrade\thoursworked\tsalary";
    cout << "\n ----------------------------------------------------------";

    for(int i = 0; i < 10; i++)
    {
        cout << "\n  " << firstnamearr[i] <<"\t\t" << lastnamearr[i] << "\t\t" << paygrade[i]
             << "\t\t" << hoursworked[i] << "\t\t" << salary[i];
    }
    cout << "\n --------------------------------------------------"<< endl;
    return 0;
}

2 个答案:

答案 0 :(得分:1)

你应该看看std::cin

答案 1 :(得分:0)

首先,你不必填充阵列只是使用:

string firstNameArr[10] = {};

然后使用:

cin >> firstNameArr[0];

但我会推荐std::vector,因为@ tobi303已经说过它只是一个动态大小的数组!

相关问题