#Need Help Understanding Some Basic Input

9 messages · Page 1 of 1 (latest)

timber eagle
#

I'm trying to solve a programming problem. It needs to take in a single number, which is the number of additional lines it will be accepting. Why does this stop in the middle of accepting input?

    int nums[] = {16, 1, 8, 0};
    int m = 0;
    int neededNums[m];
    std::cin >> m;
    
    for(unsigned int i = 0; i < m; i++) {
        std::cin >> neededNums[i];
    }
    
    for(unsigned int i = 0; i < m; i++)
        Solution(nums, neededNums[i]);
ruby acornBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

graceful hornet
#

neededNums[0];
int neededNums[m]; only in C in C++ u cant VLA

timber eagle
#

Whats up?

#

oh dang

#

hold on theres one more thing

#

Ok you were totally right, but I do have one other thing: I tried a different solution where I used a:

while(!std::cin.eof()) {

}

Loop, and for some reason, that kind of worked. I nested the other statements in there and it worked a little. Outputs were a little jumbled, but it still worked better than before. If that's too abstract to be able to help me I understand, but thank you!

ruby acornBOT
#

@timber eagle Has your question been resolved? If so, type !solved :)

timber eagle
#

!solved