I want to calculate the formula in C++ program. Put all 5 formula inside the program but just run 1 formula only.

For example, run the current ratio formula only. If you want another formula then just adjust the coding. Then the second formula will run. Just adjust inside only.

Its not a complete program just an outline. So, how to complete the program?

Formulas.h

#ifndef HEADER_H 
#define HEADER_H 

//These functions would probably be in your header file
Current_ratio()
Gross_margin()
Operating_margin()
Profit_margin()
ROE()

#endif

Formulas.cpp

 //Declaration of your functions  
    Current_ratio()
    {return (current asset / current liabilities);}

    Gross_margin()
    {return ((Revenue – Cost of goods sold) / Revenue);}

    Operating_margin()
    {return (Operating Income / Revenue);}

    Profit_margin()
    {return (Net Profit / Revenue);}

    ROE()
    {return (Net Income/Shareholder's Equity);}

Main.cpp

#include Formulas.h
    main()
    {
     Current_ratio()   //This is where you would call your one function(formula)
    }

Recommended Answers

All 7 Replies

Member Avatar for Rahul47

Be specific with your question.

Hello Rahul,

I want compute financial ratio in C++ with using header file?

Calculate in c++ program with 3 different file.

  • 2 file (cpp file)
  • 1 file (header file)

Information:

formula:-
1.Current ratio = (current asset / current liabilities)
2.Gross margin = (Revenue – Cost of goods sold) / Revenue
3.Operating margin= (Operating Income / Revenue)
4.Profit margin = (Net Profit / Revenue)
5.ROE= (Net Income/Shareholder's Equity)

Put all 5 formula inside the program but just run 1 formula only.

If you have your own coding, how to calculate in c++ program. You are welcome to show. :)

Member Avatar for Rahul47

There should be a condition on which you wish to execute different formulas ?
Without a condition how can you think of chosing a formula.

Suppose, your choice is to get current ration then formula for current ratio will be selected . . . . .same goes for rest of them.

I didn't understand. Could you please show me some examples?? plsss :)

Member Avatar for Rahul47

Just use If. . . . else or switch with Menus.

Somehow your program has to determine which of the five formulae will be used when it is executed. The program must make this decision based on parameters within the program, or it must be told exactly which formula to use based on user input. For example, the program might prompt the user to enter an integer indicating which calculation is to be made.

In any case, once the decision is made, just call the appropriate function and execute it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.