Hi, I have an assignment to create a program that asks the user to input an employee's name, the date and the amount of their paycheck and print out a simulated paycheck. I have almost everything figured out, but I keep getting a compile error. Here is my code:
I get one warning and one error:Code:#include <iostream> #include <iomanip> #include <cctype> #include <cstring> using namespace std; void getInfo(); void printLetter(char *, char *, char *, char *); void printline(char *line, int &startCount); bool doAgain(); int main() { getInfo(); return 0; } void getInfo () { char fname[20], lname[20], date[11], amount[9]; double amt; string amtTxt; do { cout << "Please enter the employee's first name:\n"; cin >> fname; fname[0] = toupper(fname[0]); cout << "Please enter the employee's last name:\n"; cin >> lname; lname[0] = toupper(lname[0]); cout << "Please enter the amount of the check:\n"; cin >> amount; amt = atof(amount); if (amt < 0 || amt > 10000) { cout << "That is an invalid check amount. Please try again.\n"; cout << "Please enter the amount of the check:\n"; cin >> amount; } cout << "Please enter the date (MM/DD/YYYY):\n"; cin >> date; cout << "Here is the way the check will print\n" << endl << endl; printLetter(fname, lname, date, amount); } while (doAgain()); } void printLetter(char *fname, char *lname, char *date, char *amount) { int position; char payee[] = "Pay to the Order of: "; char disDate[] = " Date: "; char dispAmt[] = " $"; int dp; string pay; string amtTxt; pay = amount; position = 0; printline(disDate, position); cout << right << date << endl << endl; position = 0; printline(payee, position); cout << fname << " " << lname; cout << setw(10) << dispAmt << setprecision(5) << showpoint << atof(amount) << endl << endl; dp = pay.find('.'); if (dp == 4) { for (int i = 0; i < dp; i++) { switch (amount[i]) { case '1': amtTxt = "One Thousand "; break; case '2': amtTxt = "Two Thousand "; break; case '3': amtTxt = "Three Thousand "; break; case '4': amtTxt = "Four Thousand "; break; case '5': amtTxt = "Five Thousand "; break; case '6': amtTxt = "Six Thousand "; break; case '7': amtTxt = "Seven Thousand "; break; case '8': amtTxt = "Eight Thousand "; break; case '9': amtTxt = "Nine Thousand "; break; } } } if (dp == 3) { for (int i = 1; i < dp; i++) { switch (amount[i]) { case '1': amtTxt.append("One Hundred "); break; case '2': amtTxt.append("Two Hundred "); break; case '3': amtTxt.append("Three Hundred "); break; case '4': amtTxt.append("Four Hundred "); break; case '5': amtTxt.append("Five Hundred "); break; case '6': amtTxt.append("Six Hundred "); break; case '7': amtTxt.append("Seven Hundred "); break; case '8': amtTxt.append("Eight Hundred "); break; case '9': amtTxt.append("Nine Hundred "); break; } } } if (dp == 2) { for (int i = 2; i < dp; i++) { switch (amount[i]) { case '1': amtTxt.append("Ten "); break; case '2': amtTxt.append("Twenty "); break; case '3': amtTxt.append("Thirty "); break; case '4': amtTxt.append("Fourty "); break; case '5': amtTxt.append("Fifty "); break; case '6': amtTxt.append("Sixty "); break; case '7': amtTxt.append("Seventy "); break; case '8': amtTxt.append("Eighty "); break; case '9': amtTxt.append("Ninety "); break; } } } if (dp == 1) { for (int i = 3; i < dp; i++) { switch (amount[i]) { case '1': amtTxt.append("One "); break; case '2': amtTxt.append("Two "); break; case '3': amtTxt.append("Three "); break; case '4': amtTxt.append("Four "); break; case '5': amtTxt.append("Five "); break; case '6': amtTxt.append("Six "); break; case '7': amtTxt.append("Seven "); break; case '8': amtTxt.append("Eight "); break; case '9': amtTxt.append("Nine "); break; } } } cout << amtTxt << "and " << pay.substr(dp) << " cents\n"; } void printline(char *line, int &startCount) { int charCount = 0; if (startCount >= 70) { cout << "\n"; startCount = 0; } while (line[charCount] != '\0') { if (startCount >= 60 && line[charCount] == ' ') { cout << " \n"; charCount++; startCount = 0; } if (startCount == 0) { cout << " "; startCount = 10; } cout.put(line[charCount]); charCount++; startCount++; } } bool doAgain() { char again; do { cout << "Do you want to run the program again (Y/N)? "; cin >> again; again = toupper(again); } while (again != 'Y' && again != 'N'); if (again == 'Y') { system("CLS"); return true; } else { cout << "Thank you!!!\nHave a nice day!!!" << endl; return false; } }
It looks like the << after cout is causing an error, but in my book you can use a cout statement with a string data type so I am not sure what the problem is. Can anyone help me?Code:checkwriter.cpp(81) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data checkwriter.cpp(231) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
Thanks



LinkBack URL
About LinkBacks


