Raise all values in a vector by a given percentage
#include <iostream>
#include <vector>
using namespace std;
void raise_by_percent(vector<double>& v, double p)
{
for (int i = 0; i < v.size(); i++)
v[i] = v[i] * (1 + p / 100);
}
int main()
{
vector<double> salaries(5);
salaries[0] = 3.0;
salaries[1] = 6.0;
salaries[2] = 4.0;
salaries[3] = 7.0;
salaries[4] = 5.0;
raise_by_percent(salaries, 4.5);
for (int i = 0; i < salaries.size(); i++)
cout << salaries[i] << "\n";
return 0;
}
Related examples in the same category