So we had a lecture on pointers... WOW a lot of things I dont understand.
Here is the instructions for one of my programs.
Write a program that will prompt a manager for the salaries of his employees and let the manager know the effect of giving each a 10% salary increase.
Assume the manager has 6 employees.
Use pointer notation (not array notation) for the whole program.
- in main():
-prompt the user for 6 salaries, each number must be validated using a while loop as if cant be necative or 0, store these values in an array.
- from main call a function that will incremembt each salary by 10% and store this in another array.
- From main call another function that will take both arrays, calculate the differece betweeen the original and incrementd salaries for each employee , sum these differentials and display the sum. This function should display the original salaries and the salaries with the 10% increase;
Here is my code so far... I am confused on when it comes to functions if I have to keep it in pointer notation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
//Nico Kalin OConnell
#include <iostream>
using namespace std;
void incremented(int *);
const int AMOUNT = 6;
int main()
{
int count = 0;
int original[AMOUNT];
int salary;
int *originalPtr = nullptr;
originalPtr = original;
while (count < AMOUNT)
{
cout << "Amount of sallary number " << count + 1 << ": ";
cin >> salary;
originalPtr[count] = salary;
count++;
}
incremented(originalPtr);
}
void incremented(originalPointer)
{
int incremented[AMOUNT];
int *incrementedPtr = nullptr;
incrementedPtr = incremented;
for (int count = 0; count < AMOUNT; count++)
*incrementedPtr[count] = *originalPointer[count] * 1.10;
}
void display()
{
int total = 0;
for (int count = 0; count < AMOUNT; count++)
{
total += (*incrementedPtr[count] - *originalPtr[count]);
}
}
|