array help; inputting into array

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
/*
7-10 Salary Array

Design an array that lists the salaries for ten salary grades. Write a function that will give each grade a
fixed dollar raise, and a function that gives a specified percentage increase to each grade.

Part of the assignment involves imagining what an application is for an advanced array. Hint: think of a multi-dimensional table. 
*/
#include <iostream>
using namespace std;
double perraise ( double a )
	{double percent;
	percent = a * 1.15;
	return percent;}
double fixraise ( double b )
	{double fixed;
	fixed = b + 2000.00;
	return fixed;}
int main()
{
 const int FIXEDRAISE = 10, PERCENTRAISE = 10;
 double Salary[FIXEDRAISE+1][PERCENTRAISE+1];
 double grade;
 cout << "Enter 10 salary grades and I will give each a fixed dollar and a percentage increase raise for you to compare.\n";
 for(int n =1; n < FIXEDRAISE ; n++)
  {cout << "Tell me a salary grade: \n";
  cin >> Salary[fixraise(grade)][perraise(grade)];}

  
  }


Heyy, this is my code so far. i was wondering if it seems okay so far?

i get this error error c2108:subscript is not of integral type at the last line cin >> Salary[fixraise(grade)][perraise(grade)];}
not really sure if this is what you want.
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
#include <iostream>
using namespace std;
double perraise ( double a )
	{double percent;
	percent = a * 1.15;
	return percent;}
double fixraise ( double b )
	{double fixed;
	fixed = b + 2000.00;
	return fixed;}
int main()
{
 const int FIXEDRAISE = 10, PERCENTRAISE = 2;
  double Salary[FIXEDRAISE][2]= {{0},{0}};
 double grade;
 cout << "Enter 10 salary grades and I will give each a fixed dollar and a percentage increase raise for you to compare.\n";
 for(int n =0; n < FIXEDRAISE ; n++)
  {cout << "Tell me a salary grade: \n";
	int j=0;
	cin>>grade;
        //n spot j 2 spaces 0,1 for perraise return and fixed raise return  
        //j++ increment after stored
        //j=0
	Salary[n][j++]=perraise(grade);//j =0
        //j=1 need to increment j or i could have used a for loop
	Salary[n][j++]=fixraise(grade);//j=1
       //j=2 not really need could of just left it j for this one
 }
 cout<<endl;
    for(int n =0; n < FIXEDRAISE ; n++)
  {cout << "PRINTING ARRAY.\n";
	int j=0;
	
	cout<<"["<<n<<"]"<<"["<<j<<"]"<<"P Raise: "<<Salary[n][j]<<" ";
	j++;
	cout<<"["<<n<<"]"<<"[ "<<j<<"]"<<"Fixed Raise: "<<Salary[n][j]<<endl;
 }
 
	   return 0;
  }

Last edited on
perhaps I'm missing something-
double Salary[FIXEDRAISE+1][PERCENTRAISE+1];
and
cin >> Salary[fixraise(grade)][perraise(grade)];}
- Why do you have brackets, especially around
[perraise(grade)]
??
maybe it's just a vector and I'm not use to them, or it's
an array - in which case the code won't work.

it would be better to write and debug if you had separate fnc's ;
one for fixed and another for "%"
Personally, I would have placed the 10 people and base salarys into either a table or a file, then ask at the start of the program :
What $ amt ? , & What % amt ?
then read the data
and print base-salary (n), new $ amt(n), new % amt (n)
for all 10 people- - in a FOR loop (n = 0; n <10; n++)

-1- global vars
-2- MAIN()
-3- local vars
-4- loop 10 times
-5- read value(n)
}

-6- float fnc calc dollar(amt)

-7- float fnc calc-pct(amt)



if you want to use a 2-D array,
then you could have the base salary stored in a 1-D array
float a_BaseSalary[10]= 30K, 20k, 27K, 33k, 62K, 30K, 20k, 27K, 33k, 12K

float a_IncreaseSalary[2] [10] =

0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0


a_IncreaseSalary[1] [n] = a_BaseSalary[n] * UserEnteredPercentAmt

a_IncreaseSalary[2] [n] = a_BaseSalary[n] + UserEnteredDollarAmt

Last edited on
YEAAH subzero! thanks! thats the gist of it. may i ask what is happening here?

double Salary[FIXEDRAISE][2]= {{0},{0}} at the {{0},{0}}

and
1
2
Salary[n][j++]=perraise(grade);
	Salary[n][j++]=fixraise(grade);
?
Just basically returning variable from function storing it into the array.

1
2
3
4
5
6
7
8
9
10
11

// the 0,0 stuff just sets everything in the array to 0.
double Salary[FIXEDRAISE][2]= {{0},{0}}      

 //n spot j 2 spaces 0,1 for perraise return and fixed raise return  
        //j++ increment after stored
        //j=0
	Salary[n][j++]=perraise(grade);//j =0
        //j=1 need to increment j or i could have used a for loop
	Salary[n][j++]=fixraise(grade);//j=1
       //j=2 not really need could of just left it j for this one 
Last edited on
Topic archived. No new replies allowed.