c++ - Change length of dashed line to match input string length? -
#include <iostream> #include <string> using namespace std; int main() { string name; int income; int tax; cout << "what full name? "; getline(cin,name); cout << "what annual income? "; cin >> income; if (income < 50000) { tax = income*0.33; } else { tax = income*0.38; } cout << "\t\t\t" << name << ": tax report" << endl; cout << "\t\t\t" << "-------------------------" << endl; cout << "income =$" << income << endl; cout << "tax =$" << tax << endl; system("pause"); return 0; } i line of hyphens match length of name string regardless of length. in introductory c++ class , sure there simple way this. help?
cout << "\t\t\t" << string(name.length() + 12, '-') << endl;
Comments
Post a Comment