Hi, I'm lost, I have a computer program that states, Using this algorithm (theres one listed inthe book) write a C++ function that accepts the user-entered value of money, multiples the entered amount by a percent interest rate and dispalys teh result rounded to two decimal places. Theres no examples inthe book and I'm having a hard time trying to figure out how to put an algorithm in the program. Can someone help me?
I knwo the basic beginning of the program and I knwo about cout and cin..
#include <iostream>
using namespace std;
int main()
{
double input;
double total;
cout << "Please enter an amount of money: ";
cin >> input;
and I know the percentage rate (8.675) has to be put into an equation multiplying it by the input. And it also has to dispaly th eresult rounded to two decimal places.
total=(input * 8.675) ?
I just am unsure where the algorithm goes:
step 1. Multiply the number by 10 raised to the nth
step 2. add .5
step 3. delete the fractional part of the result
step 4. Divide by 10 raised to thenth
You will have to do this after multiplying input with rate. I think they want you to use the module (%). You can only use this on integers, so first you need to multiply total by 1000 and convert it to an integer (step 1). Then check or you should add .5 using the module (step 2). I dont see the need of step 3, since you can use the founded integer for futher calculations. At the end, you have to divide the founded integer by 1000 to get back to the orginally size (step 4).