Hello guys, I'm currently attempting to create a program to translate a text file using input and output streams. I am trying to add a counter into my program to count the number of dashes/letters. I am working on the letter one now but cannot figure out how to add an int to my void. It keeps telling me that count is undefined when I call it. Here is my void function.
Sorry, but you do. Within the scope of the transformation function (*), the input parameter is declared with the name count, but only within that scope. You still need to declare a variable in the main function that gets passed into transformation.
(*) it's called a "function" by the way. The word void simply indicates that this particular function doesn't return any value.
I still cannot get it to work as it is counting incorrectly for letters.
Also, when i add the dashes counter into my function, the else's get highlighted and say they are expecting a statement.
If you want multiple statements in an if block, you need to enclose them in braces. If you don't, then only the first line is considered to be part of the block. Line 23 is considered to be after the end of the if block, which means on line 24, the else if statement doesn't follow on from an if statement.
I'd actually recommend you put braces around all your if, else, and for blocks, even if they're only one line. This sort of mistake is easy to make, and putting the braces in will help you avoid making it. I also happen to think it makes the code more readable, but that's a matter of personal opinion.