Beginner C++ student here, first programming class. I am trying to build a program which will accept a set of numbers from the user and output the sum and product of those numbers. Example:
Enter # of values to compute: 4
Enter number: 2
Enter number: 3
Enter number: 4
Enter number: 0.5
Sum is: 9.5, product is: 12
With what I have so far I get the correct sum, however, the product is zero no matter what I try. I am lost in getting that to work. Any help greatly appreciated.
You initialised product to zero, so it will always be zero on line 25.
It's great you initialised most of your variables, but this demonstrates why zero is not always a good choice. Assign the value of the firstnumber to product instead.
Thank you for that! That did it. In one version of this I had initialized it by 1, but I think I had something incorrect in the code elsewhere which was giving me an incorrect value, which threw me off and I thought initializing at 1 was the incorrect choice here.
However, it all makes sense now. Plus I gotta be more careful. Again, thank you!