2014-10-15 2 views
-1

아니다, 나는이 문제가 : 두 번째 for 루프에서첨자 값이 난 그냥 프로그래밍을 배우기 시작 배열, 포인터, 또는 벡터

  1. 를이 첨자 값이 배열 포인터, 또는 벡터 아니라고한다 .
  2. 몇 가지 이유로 나는 프로그램을 빌드 할 수 없습니다.

-

#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; 
} 
} 
+1

여기서하려고하는 것은'userEntry [secondCount]'? – P0W

+1

'int'가 배열, 포인터 또는 벡터가 아니기 때문에 프로그램을 빌드 할 수 없습니다. 두 번째 루프에서 무엇을 기대합니까? – IllusiveBrian

답변

0

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; 

컴파일해야합니다.

보조 노트로는 <string>을 절대로 포함하지 않았습니다. 포함 된 헤더 중 하나에 포함되어 있기 때문에 프로그램에서 불평하지는 않지만 일반적으로 사용중인 모든 stl 유형에 헤더를 포함하는 것이 좋습니다.

1

userEntry을 int로 선언했지만 배열로 액세스하려고했습니다. 이것이 오류가 말하는 것입니다.

+0

어떻게 해결할 수 있습니까? 나는 모른다. –

+0

@HuzaifaImran 귀하의 논리에 따라 다릅니다. userEntry가 아닌 다른 것을 출력하려고한다고 생각합니다. empNo [secondCount]를 대신 사용하셨습니까? –

0

변수가 userEntry 그래서 문이 변수 첨자 연산자를 적용 스칼라 객체

int userEntry = 0; 

로 정의 아무런 의미가 없다.

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

이 문

cout을 < < setw (9) < <이 < < userEntry < < setw (9) < < 바로 < < empName < < setw (9) < <을 떠난 것을 고려 empPay < < endl;

도 배열의 첫 번째 요소 주소를 출력하지 않는 한 아무런 의미가 없습니다.

관련 문제