right now, I am working on a problem that requires us to compare 2 different account types at a fictional bank. We have to input a value, and make calculations to show the interest rates and how much you gain/lose at the end of the year by using that type of account, etc.
Right now, I don't have very much of this problem done. There is one simple problem that I need to address. How can I make C++ show the correct number of decimals? For instance...if I enter "250" as a value, it prints "250". I want it to show all values, even if they are zero, as in "250.00".
(Ignore all of my stupid and confusing comments, and my ill-chosen variable names. )Code:#include <iostream> using namespace std; int main() { /*variables: avg daily balance; yearly account cost, income year (avg.daily * interest%) profit/loss (cost/year - income)*/ float avg; int prft; int nvcost = 0; int svcost = 12; double nvincomeyr = 0; double nvinterest = 0; double svinterest = 0; nvinterest = 0.01; svinterest = 0.015; prft = nvcost - nvincomeyr; std::cout << "Enter Average Daily Balance \n"; std::cin >> avg; nvincomeyr = avg * nvinterest; std::cout << "account \t avg daily \t cost/year \t income/year \t profit/loss\n type\t\t balance\n"; std::cout << "Netvalue \t " << avg << " \t " << nvcost << " \t " << nvincomeyr << " \t " << prft << "\n"; return (0); }
Also, is there a better way to make a "table" in code? If you see what I've done, I have a delicate balnce of \t's and spaces betweem my categories. Is there a better way to categorize data? In other words, i want it to look something like...
^This.Code:account type | avg daily balance | cost/year | income/year | profit/loss -------------------------------------------------------------------------------- NetValue 250.00 0.00 2.50 2.50 SuperValue 250.00 108.00 3.75 (104.25)
Thank you very much in advance.



LinkBack URL
About LinkBacks


