Help.

I need to write a program that calculates all the numbers from 1-100; that are odd and that are greater then 40 but smaller then 70;

If you need to write it, then write it.

What do you mean by "calculates"?

Use a for-loop.
I'm sorry the question is write a program that calculates (by this word i mean the total product example 40*41*42*43...) the product of all numbers from 1-100; However the conditions are : These numbers are odd, are greater then 40 and are smaller then 70).
You can write a for-loop, can you?
Somehow i can but i'm not getting the result i want.
Show what you have so far.
#include <iostream>
using namespace std;
int main ()
{
int i=1;
int n=100;
double p;
if ((i>40)&&(i<70))
{

do
{
p=p*i;
i=i+2;
}
while (i<=n);
cout << "Product is: "
<<p
<<endl;
}
system ("pause");
return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
int i=1;
int n=100;
double p;
if ((i>40)&&(i<70))
  {
    do
      {
        p=p*i;
        i=i+2;
      } while (i<=n);
    cout << "Product is: " << p <<endl;
  }


p is not initialized. What should it be at start?
i is 1, so this is never true.  What if i would be something nice to begin with?





Why go to 100, when less is enough?
Topic archived. No new replies allowed.