0

I just started learning programming, I have two problems:

  1. At the second for loop it says subscripted value is not an array, pointer, or vector.
  2. For some reason i cant build the program.

-

#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

const int SIZE = 100;

string inputString(string, int, int); 
void clearCIN();
double inputDouble(string, double, double); 
int inputInt(string, int, int, int);


int main(int argc, const char * argv[]) {

int empNo [SIZE];
string empName [SIZE];
double empPay[SIZE];
int userEntry = 0;
int count = 0;
int secom
cout << "Welcome to Employee management program";
for (count = 0 ; count < SIZE; count ++) {
    userEntry = inputInt("please enter a employee number;", 0, 1000, -999);
        if (userEntry == -999)
                         break;
        else
            empNo[count] = userEntry;
    empName[count] = inputString ("Please enter a name (1-15 characters)", 1, 15);
    empPay[count] = inputDouble ("Please enter the employee's pay)", 0, 100000);
}


cout << setw(9) << left << "Employee ID" << setw(9) << right << "Employee Name" << setw(9) <<    "Employee Salary" << endl;
cout << setw(9) << left << "======================" << setw(9) << right << "=========" << setw(9) << "=========" << endl;
cout << setw(9) << left << userEntry << setw(9) << right << empName << setw(9) << empPay  <<   endl;

for (int secondCount = 0 ; secondCount < count; secondCount++) {
cout << setw(9) << left << userEntry [secondCount] << setw(9) << right << empName [secondCount] << setw(9) << empPay [secondCount] << endl;

    return 0;
}
}
2
  • 1
    What you're trying to do here userEntry [secondCount] ? Commented Oct 15, 2014 at 4:26
  • 1
    You can't build the program because an int is not an array, pointer, or vector, what do you expect your second loop to do? Commented Oct 15, 2014 at 4:26

3 Answers 3

2

You declared userEntry to be an int but tried to access it as an array. This is what the error is telling you.

Sign up to request clarification or add additional context in comments.

2 Comments

How can i fix that please? I have no idea.
@HuzaifaImran That depends on your logic. I believe you're trying to output something other than userEntry. Did you mean empNo[secondCount] instead?
0

Did you intend to print empno[secondCount]?

for (int secondCount = 0 ; secondCount < count; secondCount++) {
cout << setw(9) << left << empno [secondCount] << setw(9) << right << empName [secondCount] << setw(9) << empPay [secondCount] << endl;

Ought to compile.

As a side note, you never included <string>. Your program probably isn't complaining because one of your included headers has it, but usually it's a good idea to include headers for all the stl types you are using.

Comments

0

Variable userEntry is defined as a scalar object

int userEntry = 0;

So applying the subscript operator to this variable in this statement has no sense.

cout << setw(9) << left << userEntry [secondCount] << setw(9) << right << empName [secondCount] << setw(9) << empPay [secondCount] << endl;

Take into account that this statement

cout << setw(9) << left << userEntry << setw(9) << right << empName << setw(9) << empPay << endl;

also has no any sense unless you are goung to output addresses of the first elements of the arrays.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.