Функция Void не отображается?
Тот, о котором идет речь, - это "outputfn ()", скорее всего, что-то связанное с тем, что я вкладываю в (), но независимо от того, что я пытаюсь, это не работает. Всякий раз, когда я компилирую программу, она показывает все, что я хочу вывести. *Имейте в виду, что я очень новичок в программировании, так что если это выглядит как катастрофа, пожалуйста, помогите!
#include<iostream> #include<conio.h> #include<fstream> #include<iomanip> using namespace std; void displayFirstAndLast(const std::string& firstName, const std::string& lastName); void headerfn(); string creditcardfn(); void verifycard(); void info(); void averageDailyBalancefn(double); double APRfn(); void interestfn(); void outputfn(string firstName,string lastName,double interest,double APR,double averageDailyBalancefn,double netBalance,double payment,double d1,double d2,string cc,string verify ); int main(){ headerfn(); string firstName; string lastName; cout << "Please enter your first and last name " <<endl; cin >> firstName >> lastName; displayFirstAndLast(firstName, lastName);//end input for name string cc; creditcardfn();//input for cc string verify; verifycard(); info(); APRfn(); double APRfn,averageDailyBalancefn,interest,netBalance, payment, d1, d2;cc; outputfn(firstName,lastName,interest,APRfn,averageDailyBalancefn,netBalance,payment,d1,d2, cc, verify ); //calculates inputs for netBalance, d1, payment, d2, and d1 again for //what averageDailyBalance is //this is where output will go for text file and below is rules? cout<<"press any key to continue\n"; getch(); return 0; } //****************************************************************************** void headerfn(){ //void function without parameters cout<<"=***************************************="<<endl; cout<< "* Date: April 11th 2017 *"<<endl; cout<< "* Credit Card Interest Calculator *"<<endl; cout<<"=***************************************="<<endl; cout << "\n"; //adds space to program output cout<< "This Program calculates the interest on unpaid"<<endl; cout<< "credit card balances using the average daily balance"<<endl; //outputs information for program user to know what program does cout<< "\n"; cout<<endl<<endl; //adds space to program output }//end of headerfn //****************************************************************************** void displayFirstAndLast(const std::string& firstName, const std::string& lastName){ std::cout << "You are " << firstName << " " << lastName << std::endl;} //****************************************************************************** string creditcardfn(){//value returning function string cc; cout << "Please enter the credit card number: "; cin >> cc; //prompts user to enter credit card number and inputs their entry cout << "\n"; //adds space to program output cout << "You entered " <<cc <<endl; //outputs what user entered for credit card number cout << "\n"; //adds space to program output return cc; } //where to read credit card with value returning function //****************************************************************************** void verifycard(){ string verify; cout << "If this is correct, press 0 or 1 to try again: "; cin >> verify; //prompts user to press 0 or 1 if credit card number is correct while (verify !="0"){ //prompts program to output the following if input not zero cout<< "\n"; //outputs a space cout << "Please enter the credit card number: "; //prompts user to enter their credit card number cin >>verify; //inputs what user put in for credit card number cout<< "\n"; //outputs a space cout <<"You entered " <<verify; //outputs what user put in for credit card number cout << "\n"; cout << "\n"; //outputs a space //outputs a space cout << "If this is correct, press 0 or 1 to try again: "; //prompts user to press 0 if credit card number is correct, 1 to try again cin >> verify; //inputs what user types in for if correct cout << "\n"; //outputs a space //adds space to program output }//end of while cout << "\n"; //outputs a space } //use void function to verify card //****************************************************************************** //Read the balance shown in bill (netBalance), payment made (payment), days in billing cycle (d1), and number days //payment made before billing cycle (d2) using a void function void info(){double netBalance, payment, d1,d2; cout<< "Please enter balance on credit card bill "; //prompts user to enter balance on credit card bill cin >> netBalance; //inputs netBalance, what user entered. cout << "\n"; //adds space to program output cout << "You entered $" <<netBalance <<endl; //outputs netBalance that user input cout << "\n"; //adds space to program output cout << "Please enter the payment you made: "; //prompts user to enter payment made cin >> payment; //inputs payment user enters cout << "\n"; //adds space to program output cout << "You entered $" <<payment <<endl; //outputs payment user enters cout << "\n"; //adds space to program output cout << "Please enter the number of days in the billing cycle: "; //prompts user to enter number of days in billing cycle cin >> d1; //inputs what user types for d1 cout << "\n"; //adds space to program output cout << "You entered " <<d1 <<endl; //outputs what user types for d1 cout << "\n"; //adds space to program output cout << "Please enter the number of days payment was made before billing cycle: "; //prompts user to enter number of days payment was made before billing cin >> d2; //inputs what user types for d2 cout << "\n"; //adds space to program output cout << "You entered " <<d2 <<endl; //outputs what user types for d2 cout << "\n"; //adds space to program output } //****************************************************************************** //??????????? void averageDailyBalancefn(double averageDailyBalancefn,double netBalance,double d1,double d2,double payment){ averageDailyBalancefn = (netBalance * d1 - payment * d2)/d1; } //average daily balance void //****************************************************************************** double APRfn(){double averageDailyBalancefn,APR; if (averageDailyBalancefn<100.00) { APR=5;} // Executes when the average daily balance is less //than 100.00 else if (averageDailyBalancefn<1000.00) { APR=10;} // Executes when the average daily balance is less //than 1000.000 else (averageDailyBalancefn>1000.00); { APR=15;} } // Executes when the average daily balance is greater //than 1000.000 //APR value returning //****************************************************************************** void interestfn(double averageDailyBalancefn,double APR,double interest){ interest= averageDailyBalancefn*APR/(100*12); //finds interest in relation to averagedailybalance //and APR divided by 100 times 12 }; //interest using void //****************************************************************************** void outputfn(string firstName,string lastName,double interest,double APR,double averageDailyBalancefn,double netBalance,double payment,double d1,double d2,string cc,string verify ){ cout<<"**************************************************"<<endl; cout<<"12345678901234567890123456789012345678901234567890"<<endl; cout<<"**************************************************"<<endl; cout<<"\n"; //adds space to program output cout<<firstName<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<lastName<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<' '<<cc<<endl; cout<<"--------------------------------------------------"<<endl; cout<<"FIRST NAME LAST NAME CARD NUMBER"<<endl; cout<<"=================================================="<<endl; ;cout << "\n"; //adds space to program output cout<<"Credit Card Balance...................... "<<setprecision(2)<<fixed<<netBalance<<endl; //outputs credit card balance in correct format cout << "\n"; //adds space to program output cout<<"Annual Interest Rate..................... "<<setprecision(2)<<fixed<<' '<<' '<<APR<<endl; //outputs annual interest rate in correct format cout << "\n"; //adds space to program output cout<< "Payment made............................. "<<setprecision(2)<<fixed<<' '<<' '<<payment<<endl; //outputs payment made in correct format cout << "\n"; //adds space to program output cout<< "Number of days in Billing Cycle.......... "<<setprecision(2)<<fixed<<' '<<' '<<' '<<' '<<' '<<d1<<endl; //outputs number of days in billing cycle in correct format cout << "\n"; //adds space to program output cout << "Number of Days Before Billing Cycle...... "<<setprecision(2)<<fixed<<' '<<' '<<' '<<' '<<' '<<' '<<d2<<endl; //outputs number of days before billing cycle in correct format cout << "\n"; //adds space to program output cout << "Average daily balance.................... "<<setprecision(2)<<fixed<<averageDailyBalancefn<<'\n'; //outputs average daily balance in correct format cout << "\n"; //adds space to program output cout << "Interest on unpaid balance............... " <<setprecision(2)<<fixed<<' '<<' '<<interest<<'\n'; //outputs interest on unpaid balance in correct format cout << "\n"; //adds space to program output cout<< "**************************************************" <<endl; cout<<"\n"; cout<< "Please enter 0 to exit or 1 for another customer: "; cin >> verify; } //adds space to program output //the following repeats the program using a while statement //output all using void
Что я уже пробовал:
Я пробовал изменить то, что находится в (), но я не уверен, что туда положить. Иногда он просто выдает мне ошибки, а иногда просто не появляется, когда я компилирую и запускаю.
0x01AA
Может быть, вы отформатируете код и уменьшите его до соответствующей части?
Я не думаю, что в противном случае кто-то пройдет через это ;)
NotPolitcallyCorrect
Однако извлечение cin всегда рассматривает пробелы (пробелы, табуляции, новую строку...) как завершение извлекаемого значения, и таким образом извлечение строки означает всегда извлечение одного слова, а не фразы или целого предложения.
Чтобы получить всю строку из cin, существует функция getline, которая принимает поток (cin) в качестве первого аргумента, а строковую переменную-в качестве второго
http://www.cplusplus.com/doc/tutorial/basic_io/
Richard MacCutchan
Ваша первая ошибка-использовать двойные типы для денежных значений. Что касается остального, то вам нужно точно объяснить, в чем заключается проблема.