Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Basketball program

Basketball program

Basketball program

I recently had an extra credit problem for my c++ class. Although no one got it and its too late to hand it in, I would like to know how this program could be coded. Here it is:
Have a user input the number of points they scored, then tell them how they could have scored those points.
(using cout<<"How many points: ";

Enter the amount of points: 5
You could have made a 3 point and a 2 point shot
Or you could have made a 3 point shot and two free throws
Or a two point shot and 3 free throws
Or you could have made 5 free throws.
There are three possible combinations
Please help if you can

RE: Basketball program

I haven't come upon a solution quite yet, but I have a feeling that a recursive function or two is going to be the key. The heart of the problem is a mathematical one. For starters, there are 5 possible combinations to the example you gave...

1) 1 3ptr. + 1 2ptr. = 5pts.
2) 1 3ptr. + 2 1ptrs. = 5pts.
3) 2 2ptrs. + 1 1ptr. = 5pts.
4) 1 2ptr. + 3 1ptrs. = 5pts.
5) 5 1ptrs. = 5pts.

Once the mathematics are straight, the coding itself shouldn't be too bad. I'll see what algorithms I can dig up.

RE: Basketball program

This little box may make this hard to read but the code works. I used a form instead of cout...
Let me know how it goes.


int s;
int a,b,c;
a= s;
b= s; //should be b=s div 2;
c= s; //should be c=s div 3;
int num=0;
for(int i=0;i<=a;i++){
for(int j=0;j<=b;j++){
for(int k=0;k<=c;k++){
if (i*1 + j * 2 + k * 3 == s){
Form1->Memo1->Text= Form1->Memo1->Text + "\r" +
i +" Freethrows, " + j + " Twos, " + k + " Threes";

Form1->Memo1->Text= Form1->Memo1->Text + "\r" +
"There are " + num +" ways";

RE: Basketball program

This is a probability application.

Siddhartha Singh

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close