•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 422,950 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,667 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1392 | Replies: 3
•
•
Join Date: Apr 2005
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Im having trouble with the Running product in my C++ program. Where is the question:
2. Write a program that repeatedly reads in integer values until a value less than or equal to zero is entered. For each value, it should print the product of the numbers from 1 to the given value. An ending message should be printed. Use a for statement to help compute the running product. A sample run might be (user input in bold):
Enter an integer: 3
The product of numbers from 1 to 3 is 6
Enter an integer: 9
The product of numbers from 1 to 9 is 362880
Enter an integer: 12
The product of numbers from 1 to 12 is 479001600
Enter an integer: 5
The product of numbers from 1 to 5 is 120
Enter an integer: -3
Thank Goodness!
Now here is the part in the program where i believe im having a little trouble. I'll copy and paste below where i believe my problem is occuring:
In my function definition i have this:
void print_product ( int user_number, int product)
{
int count;
product = 1;
cout << "\nThe product of numbers from 1 to " << user_number << " is " << product;
for (count = 1; count <= user_number; count++)
{
product = count * product;
cout << product;
}
And as for a example when i run this program like this ill get a answer like:
Enter an integer: 5
The product of numbers from 1 to 5 is 112624120 <---- which is incorrect.
So if anyone could help me to fix this problem i would really appreciate it.
Thank You
2. Write a program that repeatedly reads in integer values until a value less than or equal to zero is entered. For each value, it should print the product of the numbers from 1 to the given value. An ending message should be printed. Use a for statement to help compute the running product. A sample run might be (user input in bold):
Enter an integer: 3
The product of numbers from 1 to 3 is 6
Enter an integer: 9
The product of numbers from 1 to 9 is 362880
Enter an integer: 12
The product of numbers from 1 to 12 is 479001600
Enter an integer: 5
The product of numbers from 1 to 5 is 120
Enter an integer: -3
Thank Goodness!
Now here is the part in the program where i believe im having a little trouble. I'll copy and paste below where i believe my problem is occuring:
In my function definition i have this:
void print_product ( int user_number, int product)
{
int count;
product = 1;
cout << "\nThe product of numbers from 1 to " << user_number << " is " << product;
for (count = 1; count <= user_number; count++)
{
product = count * product;
cout << product;
}
And as for a example when i run this program like this ill get a answer like:
Enter an integer: 5
The product of numbers from 1 to 5 is 112624120 <---- which is incorrect.
So if anyone could help me to fix this problem i would really appreciate it.
Thank You
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- I LOST INTERNET!! I can only run internet in Safe Mode. Is it a virus? HJT LOG INSIDE (Viruses, Spyware and other Nasties)
- Symantec Email Proxy Virus and other IE self-running pages (Viruses, Spyware and other Nasties)
- IE and other programs running slow - possible virus/spyware infection: Please Help! (Viruses, Spyware and other Nasties)
- VB.Net won't run whith updated changes to program (VB.NET)
- error on running the parallel program (Java)
- Getting an Older Program to Run on Windows XP (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: a few questions... not programming..
- Next Thread: Need Help Of Programmers!!!!



Threaded Mode