Huzaifa Imran
Huzaifa Imran

Reputation: 11

Subscripted value is not an array, pointer, or vector

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;
}
}

Upvotes: 0

Views: 4007

Answers (3)

Vlad from Moscow
Vlad from Moscow

Reputation: 310980

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.

Upvotes: 0

Baher Ramzy
Baher Ramzy

Reputation: 171

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

Upvotes: 2

IllusiveBrian
IllusiveBrian

Reputation: 3214

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.

Upvotes: 0

Related Questions