0
long seats;
long no_of_guests;
    long fact=1;
    cout<<"Enter the number of seats nn";
    cin>>seats;
    cout<<"nnEnter the number of guestsnn";
        cin>>no_of_guests;
    for(int i=0;i<seats;i++)
    {
        fact*=no_of_guests;
        no_of_guests--;
    }
    cout<<"the possible combinations : "<<fact<<"nn";

this code has run successfully but there is a something that I couldn't get

first this program will run this way:

Enter the number of seats 

4

Enter the number of guests

6


the possible combinations : 360


press any key to continue..........

if I entered for example in seats 300
and in number of guests 400
then this is the output

the possible combinations : 0

my question is why the output is zero and not the actual answer

thank you
:) :)

Edited by pyTony: fixed formatting

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Momerath
0

Most likely you're exceeding the limitation of the variable, so at some point, it's counting over to 0, and then multiplies from 0 there onward.

Not much can be done about that, except perhaps storing the number inside a container or something of the like. You're not going to find a variable type that can hold a number as big as you're trying to make.

Edited by Red Goose: n/a

0

I just wanted to make sure of what I concluded and your answer helped me .....
Thank You very much
:) :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.