Hey guys,
I'm trying to write a program where the user inputs 8 numbers and the program, using a FOR LOOP, multiplies those 8 numbers and displays the result. I appreciate any feedback. **This code is very buggy and doesnt get me anywhere near where I want it.
Why don't you do it and if you are still having problems, post what you have done with a copy of the output along with a short explanation of why that's not what you expected.
@OP Well that is certainly one way of doing it. But you don't need the for loop. And you should initialise (set the start value) of any variables you have.
The for loop you had originally meant you were asking for the variables 8 times. Also starting mult =*num0 etc is the wrong way around *= as above, but even that is slightly off so you would have been getting a ridiculously large answer.
So, sticking to your original you needed something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include<iostream>
usingnamespace std;
int main() {
int num0 = 0, num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0, num6 = 0, num7 = 0, mult = 1;
cout << "Enter 8 integers." << endl;
cin >> num0 >> num1 >> num2 >> num3 >> num4 >> num5 >> num6 >> num7;
mult = num0*num1*num2*num3*num4*num5*num6*num7;
cout << "The product of the 8 numbers is : " << mult << endl;
return 0;
}
( The for loop makes it much easier. All you need to do is imagine if you had 1000 numbers. )