#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>
usingnamespace std;
double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters);
int main()
{
int numberofpennies;
int numberofnickels;
int numberofdimes;
int numberofquarters;
double total;
string continueProgram = "Y";
cout << "Please enter the number of pennies: " << endl;
cin >> numberofpennies;
cout << "Please enter the number of nickles: " << endl;
cin >> numberofnickels;
cout << "Please enter the number of dimes: " << endl;
cin >> numberofdimes;
cout << "Please enter the number of quarters: " << endl;
cin >> numberofquarters;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "The total amount of money is: " << endl;
cout << "$ " << totalValue << endl;
system("pause");
return 0;
}
double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters)
{
double total;
total = (numberofpennies * 0.01) + (numberofnickels * 0.05) + (numberofdimes * 0.10) + (numberofquarters * 0.25);
return total;
}
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>
usingnamespace std;
double totalValue(int, int, int, int);
int main()
{
int numberofpennies;
int numberofnickels;
int numberofdimes;
int numberofquarters;
double total;
string continueProgram = "Y";
cout << "Please enter the number of pennies: ";
cin >> numberofpennies;
cout << "Please enter the number of nickles: ";
cin >> numberofnickels;
cout << "Please enter the number of dimes: ";
cin >> numberofdimes;
cout << "Please enter the number of quarters: ";
cin >> numberofquarters;
cout << "The total amount of money is: ";
cout << totalValue(numberofpennies, numberofnickels, numberofdimes, numberofquarters) << "\n";
system("pause");
return 0;
}
double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters)
{
float total = 0;
total = (numberofpennies * 0.01) + (numberofnickels * 0.05) + (numberofdimes * 0.10) + (numberofquarters * 0.25);
return total;
}
I'm surprised your code even worked, since you were calling function totalValue(int, int, int, int) without it's parentheses and arguments.
You're not using string continueProgram = "Y";, what is your intention with that string? It looks like a loop flag.
Also, in your totalValue funciton, there is no need for having cout << "You have this amount of money :" << total << endl; since you return the total value to main and display it from there.
I plan on using the continueProgram to loop the progam once i start getting the program to display the correct total. I do not get what I am doing wrong here.
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>
usingnamespace std;
double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters);
int main()
{
int numberofpennies;
int numberofnickels;
int numberofdimes;
int numberofquarters;
double total;
string continueProgram = "Y";
cout << "Please enter the number of pennies: " << endl;
cin >> numberofpennies;
cout << "Please enter the number of nickles: " << endl;
cin >> numberofnickels;
cout << "Please enter the number of dimes: " << endl;
cin >> numberofdimes;
cout << "Please enter the number of quarters: " << endl;
cin >> numberofquarters;
cout << "The total amount of money is: " << endl;
cout << totalValue << endl;
system("pause");
return 0;
}
double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters)
{
float total = 0.0;
total = (numberofpennies * 0.01) + (numberofnickels * 0.05) + (numberofdimes * 0.10) + (numberofquarters * 0.25);
return total;
}
As I told you above, you're doing here the same mistake: line 34 cout << totalValue << endl; you're calling the function totalValue without its parameters and parentheses, that's why it doesn't work.
cmath and math.h are the same thing, except math.h is for C programs. Don't include it twice, just stick to cmath.
its not actually calling totalvalue, its printing its address as if a function pointer. Its one of those things that compiles and runs fine, but is totally not what you wanted.