i have a assignment that i don't have any idea how to do this question.
QUESTION:
Write a complete c++ program to do the following:
a) declare an array to store the salary of 100 employees.
b) read data into the array
c) calculate and display the number of employees with salary less than RM1000.00
d) calculate and display the number of employees with salary more than RM2000.00
e) determine and display the highest salary
I would guess that you should make a text file (for instance, 100 lines with one salary on each line). I don't know about you but I wouldn't want to enter 100 salaries every time the program is run.
i was thinking make an array thats 100 ints big, then have a for loop put in random numbers for it and use an if clause to catch ones above and below the trigger points, setting them into their own respective arrays. then set up a while loop to compare them until you have the largest one, and have it printed out at the end. unless you want it to show the same values every time, then you are going to have to make a file to read from *shrugs* either way it sounds like a fun little challenge
It would actually be easier to randomly generate the 100 salaries then to read them from a file. If "read data into the array" means reading from a file, then do that. Otherwise, I would ask for clarification.
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
ifstream inputFile("salaries.txt"); //this should contain the full path to salaries.txt
if( inputFile.is_open() )
{
//the file was opened successfully
//read the file line by line
while( inputFile.good() )
{
//read the current line as a string
string currentLine;
getline( inputFile, currentLine );
//processing code for the current line goes here
}
//close the file
inputFile.close();
}
return 0;
}