program that i couldn't understand

This is a discussion on program that i couldn't understand within the C Programming forums, part of the General Programming Boards category; hello everyone, i have to write a program that has to display the minimum amout of money exchanged between students ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    72

    Unhappy 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

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    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

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    right but i'm need the amount of money must be exchanged between the students

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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.
    Last edited by MacGyver; 03-24-2007 at 09:42 AM.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    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.

  6. #6
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    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.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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.

  8. #8
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    i'm trying to get help because i'm doing a good job and i'm stuck so please help me please


    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);
    }

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    you must give my program n=4 and and total=36.02 and the temp each time 15 15.01 3.00
    3.01

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. redirection program help needed??
    By Unregistered in forum Linux Programming
    Replies: 0
    Last Post: 04-17-2002, 05:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21