×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

(OP)
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: ";
cin>>score;

Example:
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
:::::::::::::::::::::::::::::::::::::::::::::::::
thanks

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.

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.

D

{
int s;
s=StrToInt(Form1->txtScore->Text);
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;
Form1->Memo1->Text="";
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";
num++;
}

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

This is a probability application.

Siddhartha Singh
ssingh@aztecsoft.com

#### 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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!