How to compute current 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---> Current ratio = current asset / current liabilities

Please correct me If I'm wrong. I just start study C++ program so HELP ME?? TQ :)

Recommended Answers

All 3 Replies

Somehow I suspect you're not providing nearly enough information for us to give you a helpful answer. However, as stated this can be done with a trivial function:

double current_ratio(double asset, double liability)
{
    return asset / liability;
}

That can be extended into a declaration and defnition using two files as well. First the header:

#ifndef CURRENT_RATIO_H

double current_ratio(double asset, double liability);

#endif

Then the implementation file:

#include "current_ratio.h"

double current_ratio(double asset, double liability)
{
    return asset / liability;
}

The third file would likely be your driver that contains the main function, includes the header, and uses the current_ratio function.

Hello James,

Thank you for your reply. I really appreciate it. But the program cannot run? :(

Can I ask you something? I want put other few formule to run the program. There have 10 formula in finicial ratio. So, how to put 10 formule in the program but run one formula.

EXAMPLE: In the code, write like "current ratio " then only current ratio will run by ask the value "current asset and current liabilites". If you want other formula then write in the name of formule. Just adjust the coding only. HOW?? pls help.

But the program cannot run? :(

What program? If you're talking about the code I posted, those are just snippets. It's up to you to write the rest and put it together so that it compiles.

I want put other few formule to run the program. There have 10 formula in finicial ratio. So, how to put 10 formule in the program but run one formula.

If the 10 formulae will ever be calculated separately, I'd suggest putting them in their own functions like current_ratio in my previous post. Otherwise, there's no need for separate functions unless the a formula is excessively long or complex and putting it in a function benefits readability. If that's not the case you can throw it all into a single function:

// This is a complete fabrication to exhibit a programming technique.
// Don't expect it to compile as-is or solve your problem as-is.
double financial_ratio()
{
    double ratio =
        current_ratio(some_asset, some_liability) +
        (some_value / some_delta) +
        (another_value / another_delta);

    return ratio / ratio_delta;
}
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.