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

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




Help using the for loop

 
Reply to this topicStart new topic

Help using the for loop

reivaj05
10 Apr, 2007 - 07:29 PM
Post #1

New D.I.C Head
*

Joined: 10 Apr, 2007
Posts: 3


My Contributions
The question implies (Write a program that uses a for statement to calculate and print the product of the odd integers from 1 to 15.)
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Help Using The For Loop
10 Apr, 2007 - 07:31 PM
Post #2

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 14,931



Thanked: 47 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Post your code, we don't do your homework for you.
User is online!Profile CardPM
+Quote Post

reivaj05
RE: Help Using The For Loop
10 Apr, 2007 - 07:34 PM
Post #3

New D.I.C Head
*

Joined: 10 Apr, 2007
Posts: 3


My Contributions
The question implies (Write a program that uses a for statement to calculate and print the product of the odd integers from 1 to 15.)

This is what i have so far...

CODE
#include <iostream>

using std::cout;
using std::cin;
using std::endl;
//using std::fixed;



int main()
{




// declerations

//int number;


int total=0;



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

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

User is offlineProfile CardPM
+Quote Post

keems21
RE: Help Using The For Loop
10 Apr, 2007 - 07:51 PM
Post #4

D.I.C Head
Group Icon

Joined: 3 Feb, 2007
Posts: 183



Thanked: 2 times
Dream Kudos: 25
My Contributions
I don't know C++ at all, but I do see something wrong:
CODE

int total=0;


When you have that and call
CODE

total *= number;


What you're realling doing is:
0*1*3*5*7...

To fix it, set total equal to 1 initially. That should work.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:52PM

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