![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 1
Rep Power: 0
![]() |
need help
i've been working on this program that is suppose to use four parameters named quarters,dimes,nickels and pennies, which represent the number of quarters,dimes, pennies and nickels in a piggy bank.
i have to use a function called totamt(), to return dollar value of the number of quaters,dimes,nickels, and pennies passed to it. below is what i have, if anyone could give me a few pointers on what im doing wrong that would be great: #include <iostream.h> #include <stdlib.h> #include <iomanip> int main() { float t,v; float totamt (float,float,float,float); float total, value; cout<<"enter a value"; cin>>value; cout <<"the total value is"<<total<<endl; system("PAUSE"); return 0; } float totamt(float q,float d,float n,float p,float t,float v) { if (v >= .25) t =.25; else if (v>=.10) t =.10; else if (v <=.01) t =.01; else if (v<=.05) t =.05; return totamt; ) |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Jun 2005
Posts: 92
Rep Power: 4
![]() |
please read the "How to post" thread, and please use [code] tags. If you do this, you increase the responses, and their helpfullness.
|
|
|
|
|
|
#3 |
|
Expert Programmer
|
i do not think it would be fair if i told you what you did wrong and explained it to you. But here is a version of what i thought you were trying to do. Im really not sure lol!
#include <iostream.h>
#include <stdlib.h>
#include <iomanip>
float totamt(float,float,float,float);
int main()
{
float total,tq,td,tn,tp;
cout << "how many quarters?";
cin >> tq;
cout << "how many dimes?";
cin >> td;
cout << "how many nickels?";
cin >> tn;
cout << "how many pennies?";
cin >> tp;
total=totamt(tq,td,tn,tp);
cout << endl << "the total value is" << total << endl;
system("pause");
return 0;
}
float totamt(float q,float d,float n,float p)
{
float tmpTotal;
tmpTotal+=(q*.25);
tmpTotal+=(d*.10);
tmpTotal+=(n*.05);
tmpTotal+=(p*.01);
return tmpTotal;
}EDIT: i personally did not run this code...
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jun 2005
Posts: 92
Rep Power: 4
![]() |
@Kilo: It's good you tried to help him, but you should use standard headers (iostream not iostream.h). Other than that, your code seems to work like intended.
@area: if you use kilo's code, make sure you change iostream.h to iostream, and then add the line using namespace std; after all of your includes. |
|
|
|
|
|
#5 |
|
Expert Programmer
|
i just took his code and altered it... i changed nothing with his headers sorry
![]() EDIT: and it depends on compiler also, i know MSVC++ 6.0 requires '.h'
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#6 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#7 |
|
Expert Programmer
|
yes it does.. i have used MSVC++ for 4 years you cannot include <iostream> must have '.h' there is no header directive
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Kilo, I have been using MSVC++ 6.0 for much longer than that. Would you like to see an example?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Rather than compress this and possibly deter readability, the link is directly to my site: VC++ 6.0 Compilation. It's zoomable, if your resolution needs that.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 |
|
Expert Programmer
|
all i know is that on any computer with mscv++ i have ever used typing -> #include <iostream> creates and error... period nothing i can do to change that granddaddy bro? maybe you just so happen to have a header directive? if you feel it will work send me a cpp file with it doing so... i will run it and copy paste the error?
![]()
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|