Hello if I input some numbers into this:
int main() {
int currval = 0, val = 0;
if (std::cin >> currval) {
int cnt = 1;
while (std::cin >> val) {
if (val == currval) {
++cnt;
}
else {
std::cout << currval << " occurs " << cnt << " times. " << std::endl;
currval = val;
cnt = 1;
}
}
std::cout << currval << " occurs " << cnt << " times. ";
}
return 0;
}
it wont output how many times the last value appears. I tried running through the code on paper and I found that it should print how many times the last number occurs. Its weird because if I enter some more numbers after it finds how many time each of the first group of numbers appear, it will print how many time the last value of the first group appears in the second print thing. you can compile and run it and see if you get different results. I am new to c++ so anything will help. Thanks.