for loop iterating around array to read from a file in c++

Hello,
I'm in my second semester of computer science. I've been trying to finish this project for the past 5 days but I need help to figure out some part. Would you review my code and give me some input please?
Write your questionPlease select 1, 2, 3, or 4: Search salary, Enter 1 Generate stats file, Enter 2 Print salaries, Enter 3 Quit, Enter 4
Then set up a switch statement with these cases to handle the user’s selection.
4. If the user selects the menu choice 1, ask the user for a salary, then use a for loop to search for the exact match inside your array and display result message if the match is found : “Matching salary found” and if the match is not found display: “The salary you entered is not found”.
5. If the user selects the menu choice 2, use another for loop to find the highest and lowest salary figures. Then generate a new text file called stats.txt, record the highest and lowest salary figures and save that file. Then display a message to the user: “The stats.txt file has been generated. The highest and the smallest salaries are : $5000 and $1000.”
6. If the user selects the menu choice 3, use another for loop to display all salaries to the user.
7. If the user selects the menu choice 4, exit the program. Otherwise, display the menu again. here.

[code]
Put the code you need help with here.
[/#include <iostream>
#include <iomanip>
#include<fstream>
using namespace std;
const int NUMEMPLOY = 5; // this const to be used as size of the array

int main()

{
char menu;
char quit;
int count[NUMEMPLOY];
ifstream inputFile;
inputFile.open("data.txt");

for (int i = 0; i < NUMEMPLOY; i++)
{
inputFile >> count[i];
cout << count[i] << " ";
}

if (!inputFile.eof())
cout << "Data file not found\n";
inputFile.close();

do
{
cout << "Which one of the following you like to pull out from our data file? " << endl;
cout << " 1. to search salary\n";
cout << " 2. to generate stat file\n";
cout << " 3. to print salaries\n";
cout << " 4. to Quit\n";
cout << "Enter your choice :\n";
cin >> menu;

switch (menu)

{
/********************************************************
* *
* CASE 1 *
* *
*********************************************************/
case '1':
{
int t = 0;
cout << "enter your salary.\n";
cin >> t;

bool match = false;

for (int i = 0;( i < NUMEMPLOY) && (match==false); i++)

{
if (match)
{
cout << "match found\n";
}
else
{
cout << "match was not found\n";
}
}
}
break;

/********************************************************
* *
* CASE 2 *
* *
*********************************************************/
case '2':
{
int largest = count[5];
for (int num = 0; num < NUMEMPLOY; num++)
{
if (count[num]>largest)
largest = count[num];
}
cout << " The stats .txt file has been generated. The highest and the smallest salaries are: $5000 and $1000.\n";
break;
}

/********************************************************
* *
* CASE 3 *
* *
*********************************************************/

case '3':
{
for (int i = 0; i < NUMEMPLOY; i++)

{
inputFile >> count[i];
cout << count[i] << " ";
}
}
break;

/********************************************************
* *
* CASE 4 *
* *
*********************************************************/
case '4':
{
quit;
}
break;

}
}


while (menu < 4);
cout << "quit\n";


system("pause");
return 0;
}
Last edited on
Topic archived. No new replies allowed.