Multiply all smaler numbers than number specified

closed account (EvCSLyTq)
I want to create a program that does this:
a = 7
result = 7*6*5*4*3*2*1 // until 0
cout << result
Program calculates the result of a*(a-1)*(a-2) --> until 1
I already tried but it isn't working (i tried with while loop).
I hope you understand the problem.
No for example I have not understood the problem because you did not show your code and said what is the problem with it.
closed account (EvCSLyTq)
1
2
3
4
5
6
7
8
9
10
     int a = 0;
     string word = "dog";
     int b;
     int c;
     b = word.size();
     while (a <= b){
           c = a*(a+1);
           a++;     
           }
           cout << c << endl;

If the word is dog I should get result 6, but i get number 12.
Last edited on
Variable c will always have the value of b * ( b + 1 ).
As in your example b = 3 then c will be equal to 12.

What you do is what you get.
Topic archived. No new replies allowed.