Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Use a for loop to write a program that calculates the product of 8 integers entered by the user.

the following code is not correct, Please help me

C++
#include <iostream>
using namespace std;
int main() {
	
	int n;
	int x = 1;
	int sum=0;
	cout << "Please enter the prodect of 8 " << endl;
	while (x<=8)
	{
		cout << "Please enter integers ";
		cin >> n;
		sum= sum * n;
		x = x + 1;
	}
	cout << "The sum of the prodect is = " << sum << endl;
	system("pause");
	return 0;
}
Posted
Updated 20-Oct-15 15:37pm
v2
Comments
Philippe Mori 21-Oct-15 13:39pm    
A sum is not a product. Give better name to your variables.

1 solution

C++
int sum=0; // <- this should be 1 not 0
 
Share this answer
 
Comments
Assam ALzookery 20-Oct-15 22:21pm    
can you help me to solve this problem

http://www.codeproject.com/Questions/1041881/how-to-use-while-loop-to-answer?arn=0

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900