sum equation

I believe my sum calculation is not working and I would like to know what I am doing wrong. please and thank you
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  /* the following program has a class that has 5 names, 5 salaries. 5 hire dates. the program provide 
a list of records that the user would like to access. The program calculate the number of years the 
employee has been employed */
#include<iostream>
#include <string>
using namespace std;

 class csci
 {
 	private:
 	  string name[5];
      double salary[5];
      int year [5];
      int sum [5];
      
  
   public:
   void putname(string n, int r)
    { name[r] = n; }
   string getname(int r) 
    {return name[r]; } 
    void putsal(float s, int r)
    { salary[r] = s;}
	float getsal(int r) 
    {return salary[r]; }
    void putyear(int y, int r)
    { year[r] = y; }
   int getyear(int r) 
    {return year[r]; } 
    void sum ( int y)
	{ 2017-int[y] ; }

	
};
 menu (){
 	cout << " \nWelcome to the first Project of C++ " 
 	<<"\nplease press enter to continue " <<endl;
 	getchar();
 }
 int main()
 {
 	menu ();
 	int p = 0;
 	csci  csci1;
 	
 	
 	csci1.putname("John ", 1);
 	csci1.putname("Stephen ", 2);
 	csci1.putname("Bill ", 0);
 	csci1.putname("Martin ", 4);
 	csci1.putname("Gary ", 3);
 	csci1.putsal(45457, 1);
 	csci1.putsal(45478, 2);
 	csci1.putsal(34646, 0);
 	csci1.putsal(77974, 4);
 	csci1.putsal(45000, 3);
 	csci1.putyear(1920, 1);
 	csci1.putyear(1930, 2);
 	csci1.putyear(1940, 0);
 	csci1.putyear(1950, 4);
 	csci1.putyear(1960, 3);
 	csci1.sum(1920);
 	csci1.sum(1930);
 	csci1.sum(1940);
 	csci1.sum(1950);
 	csci1.sum(1960);
 	
 	
 	
 	cout << "Please pick a number from 0 to 4"
 	<<"\n\tNumber : "; cin>>p;
 	if ( p>4)
 	cout << " Please refrain from using anything higher from 4" 
 	<<"\n Restarting program, please try again !" ;
 	
 	cout<<"\n The Name you selected is : "<<csci1.getname(p)<<endl;
    cout<<" \nThe Salary for : "<< csci1.getname(p)<< "is "<<csci1.getsal(p)<<endl;
    cout<<csci1.getname(p)<<" Was hired in : " <<csci1.getyear(p)<<endl;
    cout << " the number of years " << csci1.getname(p) << "has been employed is " << csci1.sum; 
    
    cout <<" \nThank you for using this program ";
 	
    system("pause");
    
    return 0;
}
line 30: your 'Sum' function is of type void and then does not return any value to print( call at line 79 );

in addition in the function 'sum' enter the values that are no use, because the result of 2017 -int [y] is not assigned to any variable member of the class


line 35: menu(), i think is a type void
Last edited on
Topic archived. No new replies allowed.