【发布时间】:2015-11-19 06:34:16
【问题描述】:
我正在编写一个代码来使用数组计算七名员工的总工资。这是我目前所拥有的
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
//Set all constants and variables
const int SIZE = 7; //Size of all arrays
int emID[SIZE] = {1234, 4563, 8765, 4568, 9867, 9235, 7684};
double Hours[SIZE],
Rate[SIZE],
Gross[SIZE];
int index;
Gross[index] = (Hours[index] * Rate[index]);
//Explain Program
cout << "This program calculates an employees gross pay\n";
for (Hours[index];index <= 6; index++)
{
cout << "How many hours did employee " << emID[index] << " work?\n";
cin >> Hours[index];
}
for (Rate[index]; index <= 6; index++)
{
cout << "Enter the pay rate for " << emID[index] << endl;
cin >> Rate[index];
}
for (Gross[index]; index <=6 ; index++)
{
cout << "The gross pay for " << emID[index] << " is " << Hours[index] * Rate[index];
}
}
不幸的是,程序在第一个“for”循环之后终止。有什么建议吗?
【问题讨论】:
-
index需要初始化。
-
thats not how this works. Thats not how any of this works.请再次阅读 for 循环的用法。 -
这是我的第一堂编程课...