I am writing a program for a class project. The program is to receive input from the user: first term of the series, the difference between terms, and the number of terms in the series. While I have the majority of the program completed, I have having trouble displaying the sign (+ or -) both before and after a value of 0 is returned.
I think it has to do with how when you are writing a positive number, you write a + after it, and if it is negative you write a - before it; so when going from 0 to a negative number, you write a + after and a - before the negative number after it. Can you see how to fix it?
I understand what you're saying, I've been stuck on it for a few hours now. Since you said that, could/should I insert another conditional [i]if[i] loop for lines 53 and 64? Something like
If I may also add, this current semester is the first time I've been exposed to programming. If you see something that could make my coding more efficient or concise, please let me know. I've come to enjoy it and would like to continue to improve. Thanks guys (AND GALS)
Quick tip: since the number of terms must be a positive integer, "numTerms" should be an int, rather than a double. (unless you can have 5.356 terms...)
(You could use an unsignedint, but funky things will happen if the user enters a negative number -- specifically, you'll end up with a super huge positive number.)
One idea is to make both positive numbers and negative numbers add the sign in front except for the first number if it is positive. Another option would be to "look ahead to the next term and don't place a + sign after your current term if the next is negative.