473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to convert this code into function...

my problem is to convert this code into function....could someone help me to solve these problem..???


Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4.  
  5. main()
  6. {
  7.     int n, N, year, choice = 0;
  8.     float val, value, deprec, tag;
  9.     char answer1 = 'Y', answer2 = 'Y';
  10.  
  11.     while(toupper(answer1) != 'N')
  12.     {
  13.         system("CLS");
  14.  
  15.         if(toupper(answer2) != 'N')
  16.         {
  17.             printf("\nOriginal value: ");
  18.             scanf("%f", &value);
  19.             printf("Number of years: ");
  20.             scanf("%d", &N);
  21.         }
  22.         printf("\nMethod: (1-SL 2-DDB 3-SYD) ");
  23.         scanf("%d", &choice);
  24.  
  25.         val = value;
  26.         n = N;
  27.  
  28.         switch(choice)
  29.         {
  30.             case 1:
  31.                 printf("\nStraight Line Method\n\n");
  32.                 deprec = val/n;
  33.                 for (year = 1; year <= n; ++year)
  34.                 {
  35.                     val -= deprec;
  36.                     printf("End of year %2d ", year);
  37.                     printf("Depreciation: %7.2f ", deprec);
  38.                     printf("Current value:%8.2f\n", val);
  39.                 }
  40.                 break;
  41.             case 2:
  42.                 printf("\nDouble Declining Balance Method\n\n");
  43.                 for (year = 1; year <= n; ++year)
  44.                 {
  45.                     deprec = 2*val/n;
  46.                     val -= deprec;
  47.                     printf("End of year %2d ", year);
  48.                     printf("Depreciation: %7.2f ", deprec);
  49.                     printf("Current value:%8.2f\n", val);
  50.                 }
  51.                 break;
  52.             case 3:
  53.                 printf("\nSum-of-the-Years\'-Digits method\n\n");
  54.                 tag = val;
  55.                 for (year = 1; year <= n; ++year)
  56.                 {
  57.                     deprec = (n-year+1)*tag/(n*(n+1)/2);
  58.                     val -= deprec;
  59.                     printf("End of year %2d ", year);
  60.                     printf("Depreciation: %7.2f ", deprec);
  61.                     printf("Current value:%8.2f\n", val);
  62.                 }
  63.                 break;
  64.             default: printf("NOT A VALID CHOICE");
  65.         }
  66.         printf("\n\nAnother calculation? [Y/N] ");
  67.         scanf("%1s", &answer1);
  68.         if(toupper(answer1) != 'N')
  69.         {
  70.             printf("Enter a new set of data? [Y/N] ");
  71.             scanf("%1s", &answer2);
  72.         }
  73.  
  74.     }
  75.     printf("\nNormal Termination... ");
  76.  
  77.     system("PAUSE");
  78. }



please help me to solve this problem...,.thank you...
Mar 28 '10 #1
1 1531
Banfa
9,065 Expert Mod 8TB
It's already in a function, main(). You need to be more precise about which bit of the code needs to be in a separate function.
Mar 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Peter Kwan | last post by:
Hi, I believe I have discovered a bug in Python 2.3. Could anyone suggest a get around? When I tested my existing Python code with the newly released Python 2.3, I get the following warning: ...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside...
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
9
by: ballygowanboy | last post by:
ok, so i've my front end shop code almost working, the quantity and price all add up........ now i need to add a curency conversion function, euro (default), dollar, and uk pound. right, i'm not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.