Hi I'm trying to write a simple code that returns how many times a number was entered by the user. Problem is if I type in "1 1 2 2 3 3" it'll return everything but the last set(two 3's). So I haven't written it properly when it comes to the second set of variable. I'm not sure where write it so it displays them.
Can you re-write the code so you take in both inputs in a single loop (eliminate the other while-loop), test if they are equal, and then output the message "you entered 'x' 'cnt' time"?
I'm not sure. Maybe, but I have very limited practise atm.
I was under the impression the first while loop takes the first value, then builds from that inital code base. The second while loop allows it to loop multiple times while maintaining the first input value for comparison. That way once there is a difference in values, it prints the cout details, transfers the second value (input2) to input, resets the counter and continues on with the inital while loop if there are anymore input values entered. If I only had 1 while loop, how would I be able to increment the values beyond one addition ++.
If I'm understanding all of this right that is.. I'm still confused as to why it's ignoring the final values I enter unless I enter in a new set of values a second time.
I'm just learning, so I want to learn how to do both. Initially it would be your Option 1, but option 2 would be the next step. I assume option two involves creating variables and storing associated counters for each?
In anycase, option 1 is what I'm attempting to do atm. With my code if I enter in 1 1 3 3 4 1 4 5 - it excludes 5 in the output until I enter in more input a second time.
Option 2 looks like more fun :) but first things first