Ecco altri esercizi su cui mi ero bloccato l'altro giorno:
18. Consider the following statements:
int total_pennies = static_cast<int>(100 * total + 0.5);
int total_tax_pennies = static_cast<int>(100 * total * tax_rate + 0.5);
Introduce a function to reduce code duplication.
Questo non capisco proprio cosa mi chiede
19. Consider this code that prints a page number on the left or right side of a page:
if (page % 2 == 0) { cout << page << endl; }
else { cout << setw(80) << page << endl; }
Introduce a function with return type bool to make the condition in the if
statement easier to under stand.
20)Consider the following function that computes compound interest for an
account with an initial bal ance of $10,000 and an interest rate of 5 percent:
double balance(int years) { return 10000 * pow(1.05, years); }
How can you make this function more reusable?
di questo ho fatto una bozza ma mi da errore
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
/*Consider the following function that computes compound interest for an
account with an initial bal ance of $10,000 and an interest rate of 5 percent:
double balance(int years) { return 10000 * pow(1.05, years); }
How can you make this function more reusable? (5x1000)/100
*/
using namespace std;
double balance(int years, int rate)
{
double interest = (years*rate)/100;
return interest;
}
int main()
{
double x,y,result;
cout << "Inserisci la crifa iniziale: ";
cin >> x;
cout << endl << "Inserisci il tasso di interesse in percentuale (es: 5 significa 5%): ";
cin >> y;
result = double balance(x, y); //QUI MI DA ERRORE
cout << endl << "Il tasso di interesse e' di : " << result << "annui." << endl;
system("PAUSE");
return EXIT_SUCCESS;
}