Necesito escribir un progtwig para una tarea para el hogar para calcular los costos de matrícula y la salida debe tener el formato tal que con el relleno de puntos y el espacio después del signo de dólar
Student Name: Name goes here Address: Address goes here Number of credits: .......... 5 Cost per credit hour: ............ $ 50
Mi código hasta ahora es:
#include #include #include #include using namespace std; double const REG_FEE = 700, STUDENT_ASSEMBLY_FEE = 7.19, LEGAL_FEE = 8.50, STUDGOV_FEE = 1.50, LATE_FEE_PERCENTAGE = 0.015; int main() { double num_credits, cost_per_credit, tuition_total, late_charge, amount_due; string student_name; string student_address; string student_city_state_ZIP; ifstream info; info.open ("info.txt"); getline (info, student_name); getline (info, student_address); getline (info, student_city_state_ZIP); info >> num_credits; info >> cost_per_credit; tuition_total = num_credits * cost_per_credit + REG_FEE + STUDENT_ASSEMBLY_FEE + LEGAL_FEE + STUDGOV_FEE; late_charge = tuition_total * LATE_FEE_PERCENTAGE; amount_due = tuition_total + late_charge; cout << "Tuition and Billing Program by Neal P." << endl << setw(18) << "Student Name:" << student_name << endl << setw(18) << "Address:" << student_address << endl << left << setfill('.') << endl << setfill(18) << "Number of Credits:" << setw(5) << "$" << num_credits << endl << setfill(18) << "Cost per Credit Hour:" << setw(5) << "$" << cost_per_credit << endl << setfill(18) << "Tuition Cost:" << setw(5) << "$" << tuition_total << endl << setfill(18) << "Registration Fee:" << setw(5) << "$" << REG_FEE << endl << setfill(18) << "MSA Fee:" << setw(5) << "$" << STUDENT_ASSEMBLY_FEE << endl << setfill(18) << "Legal Services Fee:" << setw(5) << "$" << LEGAL_FEE << endl << setfill(18) << "Student Government Fee:" << setw(5) << "$" << STUDGOV_FEE << endl; return 0;
}
Cuando compilo obtengo un error muy largo, algo como: “En la función ‘int main ()’: / Users / nealp / Desktop / machine problem 2.cpp: 41: error: no hay coincidencia para” operator < *) std :: operator < &) ((std :: basic_ostream> *) ((std :: basic_ostream> *) ((std :: basic_ostream> *) std :: operator << "que continúa. ¿Es este un problema con mi uso de setw y setfill juntos? Sé que setfill solo se debe declarar una vez y setw solo es efectivo en la siguiente línea de salida, pero definí setfill cada vez porque estaba usando setw antes.
std::setfill
es una plantilla de función y su argumento de plantilla se deduce en función del tipo de argumento al que se lo pasa. El tipo de retorno no está especificado; es un tipo de proxy definido por la implementación que establece el carácter de relleno en el objeto de flujo y permite un mayor encadenamiento de llamadas operator<<
del operator<<
. También depende del tipo con el que se setfill
instancia de setfill
.
El tipo de literal 18
es int
por lo que setfill
devuelve algún tipo no relacionado para el que no hay operator<<
disponible.
No estoy seguro de lo que quisiste decir con setfill(18)
, supongo que lo has confundido con setw(18)
.
Simplemente reemplace setfill(18)
en su código, esa es la razón del error de comstackción.
Aquí está la parte de impresión mejorada para adaptarse a los requisitos,
cout << "Tuition and Billing Program by Neal P." << endl << "Student Name:" << student_name << endl << "Address:" << student_address << endl <