# program that i couldn't understand

• 03-24-2007
elton_fan
program that i couldn't understand
hello everyone,
i have to write a program that has to display the minimum amout of money exchanged between students (for example three students travled to a place and everyone pay for a specific thing then after the trip they meet to exchange money) could you please give me the formula to compute the minimum amout of money to be exchanged
• 03-24-2007
ssharish2005
Code:

Total Money spent = ( Spent on coach) + ( Dinner in Resturent ) + ( Coffee in Cafe ) + ( Went for cinema ) + ( Back to town on Rail )

Each person share = ( Total Money  Spent) / 3

If i understand you well, this is what i will come out with. Sustitute some value for all those variables and calculate.

ssharish2005
• 03-24-2007
elton_fan
right but i'm need the amount of money must be exchanged between the students
• 03-24-2007
MacGyver
No, I'm not going to give you a formula because I'm sick and tired of lazy students trying to get their assignments done by other people on these kind of forums. If you're not a student and this is not for an assignment, that's even worse. ;)

Read the requirements again. Try to define the problem in your own words. Forget for a moment that you have to program it. How would you figure out the answer intuitively? Come up with a way to solve it manually on paper using basic math. Then define your strategy in a simple way with each step explicitly declared.

After you did all this, then you can always begin the process of starting to program it. Here's the basic skeleton of a good starting of a C program:

Code:

#include <stdio.h>
int main()
{
return 0;
}

Get to it. ssharish2005 gave you a good hint as to how to compute it. The basic idea behind the code given will give you what they should have been spending. You should already have what they did spend. Now you need to come up with what they need to spend.
• 03-24-2007
sl4nted
so take the difference between what a person spent and their share. some will be positive and some will be negative. Thats the amount that needs to be exchanged by each person.
• 03-24-2007
KONI
Quote:

Originally Posted by MacGyver
No, I'm not going to give you a formula because I'm sick and tired of lazy students trying to get their assignments done by other people on these kind of forums. If you're not a student and this is not for an assignment, that's even worse. ;)

Please consider that, even though the more active members on this forum encounter a lot of those threads per day, the newly registered member asking for help, even if it is against the forum policy, has only been to this board for several minutes and doesn't deserve a harsh answer.

I would suggest that, if you feel that someone violates the homework rule, to either ignore that thread completely or to give a standard response with a link to the guidelines.
• 03-24-2007
MacGyver
Quote:

Originally Posted by KONI
Please consider that, even though the more active members on this forum encounter a lot of those threads per day, the newly registered member asking for help, even if it is against the forum policy, has only been to this board for several minutes and doesn't deserve a harsh answer.

He's been registered since January. I know we're dealing with time being displaced due to the forum backup, but he's been here for 3 months.

Quote:

Originally Posted by KONI
I would suggest that, if you feel that someone violates the homework rule, to either ignore that thread completely or to give a standard response with a link to the guidelines.

I actually have helped people with homework issues. I have no problem doing it, provided they are the ones doing the work. I have a major problem, however, with people that do not even attempt to work on the problem at all.

Learning how to code is more then just actually writing down statements in a particular computer language. To be a successful programmer, you need to be able to properly research and think in a logical manner. Getting blanket assistance for every problem here is not the way to achieve that.

This is the way I figure it: Don't understand an assignment? That's what the professor and any teaching assistants are for. Don't know how to program it? That's what the entire course is for, including numerous books and even the tutorials on this site.

Stuck on a particular problem, yet, you can articulate exactly what the problem is, what you expect the code to do, and what it is actually doing? That's what this forum is for. ;)
• 03-24-2007
elton_fan

Code:

#include<stdio.h>
int
main(void){
int n,count,k;
double total_money,temp,min_exch,min,rate,max;
count=1;
k=2;
printf("please enter the number of student\n");
scanf("%d",&n);
printf("please enter the total money spent in the trip\n");
scanf("%lf",&total_money);
rate=total_money/n;
printf("%f",rate);
while(count<=n){
min=0;

printf("please enter the amount of money spent by each one\n");
scanf("%lf",&temp);
if((temp+min_exch)<rate){

{
max=0;
if(temp>max)
max=temp;
}

min_exch=0.000;
while((max+min_exch)<rate){
min_exch=min_exch+0.001;
min=min_exch*k;

printf("the minimum exchage is %.2f\n",min);

}

count++;

}

else
count++;
}

return(0);
}

• 03-24-2007
elton_fan
you must give my program n=4 and and total=36.02 and the temp each time 15 15.01 3.00
3.01
• 03-24-2007
dwks
Seems to me that you do count++ no matter what, so why duplicate the code?

Your code seems overly complex for such a (relatively) simple problem. I can't understand your algorithm at all. Perhaps you should post a longer description of the problem, or re-think your algorithm.