Question: Make this code work, C + + . / / ( 1 ) write the preprocessing directives # include / / cin, cout, endl #

Make this code work, C++.//(1) write the preprocessing directives
# include // cin, cout, endl
# include // string variables
# include // file processing
# include // clear screen
using namespace std;
//(2) open the scope of the main() method
int main()
{
//(3) declare and initialize the variables
static char chrName[100]; // employee name
double myExpenses; // individual expense
char myLabels[100]; // expense label
int index =0; // loop control variable
int number =0; // number of expense items
ofstream fout; // file stream output
//(4) file variable initialization
fout.open("data.txt");
//(5) clear the screen ( for Windows users )
system("CLS");
//(6) request the employee name
cout << "enter the employee name: "<< endl;
cin.getline(chrName,100);
//(7) request the number of expense items
cout << "enter the number of expense items: "<< endl;
cin >> number;
cin.ignore(); // skip [Enter] entry from keyboard;
//(8) open the looping structure
while (index < number)
{
index++;
//(9) request the user for an expense item
cout << "enter the type of expense: "<< endl;
cin.getline(myLabels,100);
cout << "enter the amount of expense: "<< endl;
cin >> myExpenses;
//(10) write the data to a text file
fout << chrName <<":"<< myLabels
<<":"<< myExpenses << endl;
cin.ignore(); //skip [Enter] entry from keyboard;
//(11) close the scope of the while() loop
}
//(12) close, i.e. dismiss, the file object
fout.close();
//(13) close the scope of the main() method
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!