Hello Everyone...
This is my first post here... I'm new to C++ and I have a home work program that has me confused.
My first problem is my program just hangs.. I can type in the file name and then it hangs.. If I do put in the incorrect name it traps the error. I know my program is pretty screwed up. I worked on this all day yesterday.
Secondly, I need to use a class? How can I create a class out of this program? (classes totally confuse me)
Thanks for your help...
Code:#include <iostream> #include <iomanip> // for set precision #include <fstream> // for file i/o #include <string> #include <istream> using namespace std; //***** Main Program ***** int main () { //***** Variable and Const Declaration *****// string FirstName; string LastName; float PersonalIncome; ifstream IncFile; string FileName; float FamilyIncome; int FamilyMembers; float AGI; float TaxRate; //float TaxAmount; string FamilyName; const float Deduction = 5000.00; const float MaxIncome = 60000.00; cout <<fixed<<showpoint // Set floating point; <<setprecision(2); // Set up output format //***** File Name Input and Read *****// cout << "Name of the File to read: "; cin >> FileName; IncFile.open(FileName.c_str()); //opens the input file if (!IncFile) { cout << "***** Can't open input file *****" << endl; return 1; }; //***** Intilization of variables *****// FirstName = " "; LastName = " "; FamilyName = " "; PersonalIncome = 0.00; FamilyIncome = 0.00; FamilyMembers = 1 ; AGI = 0.00; IncFile >> LastName >> FirstName >> PersonalIncome; while(IncFile) { getline(cin,LastName); getline(cin,FirstName); cin >> PersonalIncome; if (LastName==FamilyName) { FamilyIncome=FamilyIncome + PersonalIncome; FamilyMembers++; } else AGI = FamilyIncome - (Deduction * FamilyMembers); if (FamilyIncome < MaxIncome) {TaxRate = (AGI/100000); } else {TaxRate = (AGI * .50);}; cout << LastName << setw(2) << TaxRate; cout << endl; FamilyName = LastName; //reset variables FamilyIncome = 0.00; FamilyMembers = 1 ; AGI = 0.00; } return 0; };