배열 b[]
에 숫자를 numCase
번 입력하고 싶습니다.왜 내 배열에 입력 값이 저장되지 않습니까?
#include <iostream>
using namespace std;
//entry point
int main()
{
//Declarations
int b[20]; // array size 20 (limit of inputs)
int c = 0;
int numCase;
int input;
cout << "ENTER NUMBER OF CASES (MAXIMUM NUMBER OF 20): \n";
cin >> numCase;
//checks that numCase is less than or equal to (20) and does not exceed
if (numCase < 21)
{
// gets input number based on the numCase
do
{
cout << "ENTER A NUMBER (MAXIMUM OF 5 DIGITS): \n";
cin >> input;
cout << "\n";
b[c] = input;
c++;
} while (c != numCase);
cout << b[c] ; // this is my problem it OUTPUTS RANDOM VALUE,
//but i can see on my watch list that b has the values of my input.
}
}
희망이 도움하지만 난 B를를 법원 때 [C] 모두 내가 WA있어 첫 번째 입력. 내가 2 개의 입력을 원한다고 말하자면 ex. 20 및 700 my cout은 20 만 표시됩니다. – user3739376
예 - for 루프를 사용하고 카운터를 증가시켜 모든 배열 요소를 표시하는 것이 가장 좋습니다. – suspectus
if if (b (counter) <101) 및 입력 값이 20과 700 인 if 문을 사용해야합니다. 어떻게하면 700이 해당 진술 안에 들어 가지 않도록 할 수 있습니까? 나는 그것을 시도했다 700 안으로 들어간다 – user3739376