Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,131 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,784 people online right now. Registration is fast and FREE... Join Now!




For statement program

 
Reply to this topicStart new topic

For statement program, I need to do this code using (for) only but im stuck.

reivaj05
12 Apr, 2007 - 03:47 PM
Post #1

New D.I.C Head
*

Joined: 10 Apr, 2007
Posts: 3


My Contributions
The progam indicates that i need to use for to print out the product of the odd integers from 1 to 15 odd.

so for (e.g) 1*3-5-7*9....*15= 2027025 <---- this is the answer . so far this is all i got







CODE

int main()
{

int total=0;

for (int number=1;number<=15;number+=2)
    total= ????????????????

cout<< "Number is " << total << endl;

User is offlineProfile CardPM
+Quote Post

GWatt
RE: For Statement Program
12 Apr, 2007 - 04:09 PM
Post #2

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,178



Thanked: 18 times
Dream Kudos: 450
My Contributions
You have the for loop syntax down, it's just the inside that's bothering you. I would personally set 'total' to one, and then use the times-equals operator in conjunction with 'number.'
CODE
int total = 1;
for (int number = 1; number <= 15; number++)
    total *= number;
cout << "Number = " << total << endl;

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:22PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month