When question

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

I am studying c++. While writing the sentence, is there any? That's why I ask you this question.

#include <stdio.h>

int main (){

  int x = 0, result = 0;

  while (1) {

    scanf_s("%d", &x);
    result = result + 1;
    if (x == -1){
    printf("%d attempted.", result-1);
    break;
    }
  }
}

Of course, if you put an integer other than -1, you'll get input continuously, and you'll know what the attempt is.

Is there a code that tells you which integer you tried at, not the number of times you tried in the while statement?

I'm still a beginner, so I don't know how to organize it.

c++ c

2022-09-20 11:05

1 Answers

If you stack the inputs that you received as you go through the repetition one by one in the array, you'll see what the next input was through the index. It would be nice if it could be a hint for you to come up with an algorithm.

I didn't elaborate on the code because I knew how bad it was to show the beginner the right answer. If you ask me questions in the comments, I'll answer them.


2022-09-20 11:05

If you have any answers or tips


© 2022 pinfo. All rights reserved.