Thread: Help with program pleeeasseee!!!

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    1

    Help with program pleeeasseee!!!

    calculation depreciation costs

    enter a cost (dollars) for an asset along with its expected life (years)

    then the resulting depreciation amount and book value (remaining value after depreciation) should be calculated and displayed for each year of the assest's lifetime - using both methods

    methods:
    straight-line method: calculates depreciation amount (cost / expected_life) that is equal amounts spread out over the lifetime of the item. each year the book value is subtracted by the depreciation amount

    sum-of-digits: uses the sum of the years' digits and varying proportions to determine each year's depreciation amount.

    would like to be able to enter varying cost and expected life pairs before deciding to end the program





    must use sentinel control repeition when entering values for the cost of the assest and its expected life until the user wishes to end the program

    nested repetition must be used for the counter-controlled loop dependent on the expected life

    PLEASE PLEASE HELP!!!!

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    So what have you coded so far? We won't write the code for you but we will help you with what you have written..
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  3. #3
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Here you go, bro

    Code:
    #include <iostream>
    #include <iomanip> // Required for nice output formatting
    
    // Declare variables.
    int lifetime, cost;
    
    // main function
    int main(int argc, char** argv)
    {
    	while (argv!=0)
    	{
    		// print instructions to the user.
    		std::cout<<"Enter the lifetime followed by the cost using whole numbers."<<std::endl
    		<<"Enter a non-numeric value to quit."<<std::endl; if(!(
    		// get user input
    		std::cin>>lifetime>>cost))
    	{
    	return 0;
    }
    
    (int) main((int) !argc, (char**) !argv);
    }
    	argc||
    	// print out the results.
    	std::cout<<"Year    Value (straight-line)     Value (sum of digits)"<<std::endl;
    	std::cout<<std::setw(7)<<std::left<<argc
    	<<std::setw(22)<<std::right<<cost-1.0*argc/lifetime*cost
    	<<std::setw(26)<<cost-1.0*cost*argc*((lifetime
    	<<1)-argc+1)/(lifetime*lifetime+lifetime)
    	<<std::endl;
    	return 0
    	||(argc-lifetime)&&main(argc+1,0);
    }
    jeffcobb might be pretty lame, but I'm cool and I'm always willing to share the wealth.
    Last edited by NeonBlack; 02-23-2010 at 03:38 AM.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by NeonBlack View Post
    Here you go, bro

    Code:
    #include <iostream>
    #include <iomanip> // Required for nice output formatting
    
    // Declare variables.
    int lifetime, cost;
    
    // main function
    int main(int argc, char** argv)
    {
    	while (argv!=0)
    	{
    		// print instructions to the user.
    		std::cout<<"Enter the lifetime followed by the cost using whole numbers."<<std::endl
    		<<"Enter a non-numeric value to quit."<<std::endl; if(!(
    		// get user input
    		std::cin>>lifetime>>cost))
    	{
    	return 0;
    }
    
    (int) main((int) !argc, (char**) !argv);
    }
    	argc||
    	// print out the results.
    	std::cout<<"Year    Value (straight-line)     Value (sum of digits)"<<std::endl;
    	std::cout<<std::setw(7)<<std::left<<argc
    	<<std::setw(22)<<std::right<<cost-1.0*argc/lifetime*cost
    	<<std::setw(26)<<cost-1.0*cost*argc*((lifetime
    	<<1)-argc+1)/(lifetime*lifetime+lifetime)
    	<<std::endl;
    	return 0
    	||(argc-lifetime)&&main(argc+1,0);
    }
    jeffcobb might be pretty lame, but I'm cool and I'm always willing to share the wealth.
    Geez and I thought there was some rule about doing homework around here and encouraging folks to at least try coding a solution...when I first got here I did what Neon did (whipping out tested ready-made solutions when people just posted the problem w/o even trying to solve it) and got my knuckles slapped for it...

    Some days you just can't win...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    There's a difference between writing simple off the shelf answers that could be handed in without further effort from the OP, and the kind of obfuscated "delights" that Neon posted.

    Whilst it may functionally solve the OPs problem, it's not an answer they can immediately use - bad bad Neon

    The OP might try to hand it in, but it would be a dead giveaway that they didn't write it, and they would have some serious 'explaining' to do.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Technically, NeonBlack's shared wealth is not even a valid C++ program.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Salem, I like that. I think I might call them "delights" from now on too.

    laserlight, thanks for pointing that out. That's something I didn't know, have never needed to know, and gcc accepts it without -pedantic. You can never have too much limitedly useful knowledge.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM