Question about my program code

Home Forums C Programming Question about my program code

This topic contains 0 replies, has 1 voice, and was last updated by  happyherlean 10 years, 4 months ago.

  • Author
  • #2023


    I’m a beginner in C++ The program below inputs sevaral positive numbers with decimal points, analyzes these numbers, and outputs the result. The program works fine. But I wanted to make sure that a user puts only positive numbers or -1 to end repetition loop. So, I created couple of functions that would check the numbers, return them in case if they are positive or equal -1. In case they are negative, the program would output warning message and ask to enter the number again. It also work fine, but if I enter negative number and than enter positive number, the program saves negatives number, although I return the value from the function. Can anyone please explain me where my error is. Thanks!

    P.S. I know that it’s possible to use template functions when you have a function that does the same operations, but with different types of variables. Can I use this concept with my problem when I have similar functions, but different names of variables? If yes, can anyone please show me how? Thanks!

You must be logged in to reply to this topic.