Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The one in question is the "outputfn()" it is likely something to do with what I am putting in the (), but no matter what I try it is not working. Whenever I compile the program, it shows everything put the output I want. *Keep in mind I am VERY new to programming so if this looks like a disaster please help!

C++
#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


What I have tried:

I've tried changing what is in the () but I am not sure what to put in there. Sometimes it just gets me errors, other times its just not showing up when i compile and run.
Posted
Updated 19-Nov-17 4:27am
v3
Comments
[no name] 15-Apr-17 14:07pm    
Maybe you would Format the code _and_ reduce it to the relevant part?
I don't think that otherwise sombody will go through it ;)
[no name] 15-Apr-17 15:31pm    
However, cin extraction always considers spaces (whitespaces, tabs, new-line...) as terminating the value being extracted, and thus extracting a string means to always extract a single word, not a phrase or an entire sentence.

To get an entire line from cin, there exists a function, called getline, that takes the stream (cin) as first argument, and the string variable as second

http://www.cplusplus.com/doc/tutorial/basic_io/
Richard MacCutchan 16-Apr-17 3:13am    
Your first mistake is to use double types for monetary values. As to the rest, you need to explain exactly what the problem is.

1 solution

First of all you mix functions and variables.
void averageDailyBalancefn(double& balance,double netBalance,double d1,double d2,double payment){
 
   balance = (netBalance * d1 - payment * d2)/d1;
}


I have deliberately changed the name of the parameter. If you want to get the result use & after the type and call this function like that:
double averageDailyBalance;
averageDailyBalancefn(avarageDailyBalance, 500, 0.5, 0.6, 1000); // use your values, it's just and example
std::cout << averageDailyBalance << std::cout;


You may have defined the function differently:
double averageDailyBalancefn(double netBalance,double d1,double d2,double payment){
 
   return (netBalance * d1 - payment * d2)/d1;
}


Then you call it like this:
double averageDailyBalance;
averageDailyBalance = averageDailyBalancefn(avarageDailyBalance, 500, 0.5, 0.6, 1000);


Don't mix up variable names and function names.
Define a variable, assign a value to it if needed, call a function with passing parameters from variables, get the results.
Print the results out. See that you get correct results.
Don't try to write big chunks of code and then try to debug them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900