Unless you have something that is not in the question, the invalid number does not make sense. Why would the smaller number be invalid? It can happen invalidity of the number and it would be nice to treat it, but as it is exercise I let it go, just do not take as correct for real codes.
In your account you are counting how many times the larger number has been changed, after all you are increasing a counter every time you find a new bigger one. That’s not what the question is. When exchanged for a larger number the count should start again by that time that larger number only appeared once. This is called logic. When the number is equal to the largest then then you should increment the counter. If the number is smaller it is to do nothing.
You can’t ask the person to type 00, this is not a text, 00 is the same as 0. Or even gives but then would have to ask for a text and then do the conversion, it is a lot of work. Maybe it was the case to ask for a negative number to get out of the loop, if you can a negative too, then complicates and would have to have another exit solution.
The test you were doing didn’t stop anyone from typing something negative as a valid value.
I gave an organized and simplified too.
#include <stdio.h>
int main () {
int quantidade = 0, maior = 0;
printf("Ao finalizar, digite '0', sem aspas, para obter o resultado.\n\n");
while (1) {
printf("Insira um numero: ");
int num;
scanf("%d", &num);
if (!num) break;
if (num > maior) {
maior = num;
quantidade = 1;
} else if (num == maior) quantidade++;
}
printf("Maior numero: %d - quantidade de vezes: %d\n", maior, quantidade);
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
I’m not sure I understand the question. Do you need to count the number of times the "record" has been broken? Or count the number read until the "record" is broken?
– user201641
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero