![]() |
|
#1
|
|||
|
|||
showing £1.00Hey guys please help im going insane here.
I have to multiply total no of cans purchased with cost and display the cost price. the problem i am having is it display the cost as £0.5 or £1..when i want it to display as £0.50 or £1.00 i know this is prob something real simple.. but what am i doing wrong my variables are floats.. help please xx from a damsel in distress.. ;-) my program so far is as below.. i know it not neat but i have to include certain things CPP / C++ / C Code:
Last edited by LuciWiz : 06-Jul-2005 at 08:49.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#2
|
|||
|
|||
|
Quote:
You can use formatting flags and functions like this for each item: CPP / C++ / C Code:
The setiosflags() , resetiosflags and setprecision() functions obtained by including the iomanip header Question: why do you #include <process.h>? Here's an answer to the question you didn't ask: Didn't you get compiler messages for this stuff? CPP / C++ / C Code:
In fact you don't use the return value from this function (and it's a good thing you don't) So, why not just make it a void type and delete all of the returns? It is recommended that you tell us about all of the compiler messages you got. Sometimes it's important (but in this case no harm, no foul). Here's a suggestion that won't necessarily make this program run better, but is a good habit to get into: Use standard C++ header <iostream>, not <iostream.h> So the top of your program might look like this: CPP / C++ / C Code:
Regards, Dave |
|
#3
|
|||
|
|||
|
Thank you so much dave xxx
I will try this out.. oh and i had the process.h file cos i had tried something else and it failed and i forgot to take it back out doh! and no i got no errors for the return values.. but i will void the function again something i was playing about with! as i am sure u can tell i still at college learning c++ thank you again xx |
|
#4
|
|||
|
|||
|
Quote:
Well, some compilers warn you about "unreachable code", but I guess some don't. The thing is that functions can return only one value (or none if its type is "void"). Furthermore, once a "return" statement is executed, program flow goes back to the calling function. (That is, all statements after the first "return" is encountered are ignored.) So, your program is not illegal or undefined behavior or anything other than bad style. (But shows a lack of understanding of program flow and use of functions.) Quote:
Well, no one was born knowing this stuff. You have made a great start, I think. Good Luck! Regards, Dave |
|
#5
|
|||
|
|||
|
thanx for your words of encouragement... xx
unfortunalty (i cant spell for one!) i tried to reset flags and it didnt bring up an error but it still showed as £1 or £0.5 i ven read up on internet about this resetting flag thing.. to no aval |
|
#6
|
|||
|
|||
|
Quote:
I showed a possible sequence for one item. Similar code goes for each and every item. How about posting your current code? Also, what Operating System and Compiler are you using? (Sometimes it helps us to get to the bottom of things.) Regards, Dave |
|
#7
|
|||
|
|||
|
i dont it thanx to u dave! once i knew what i was looking for i could research it on the internet.
i achieved it by cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); just before display in my sales loop and it done it for all of them! oh and incase u interested i use borland antique compiler.. cos this is what we use at college so i dont have much choice in that! even tho it dont seem to reconise try and catch!!! oh well beggers cant be users! and can i just say i am so chuffed with myself now i have got my program working!! i try to tell my boyfriend and daughter but they just dont understand! i am quite pleased with my end result and i hope i get a good remark from my tutor now or i think my pride will be hurt! thanx again dave thank you so much xxx |
|
#8
|
|||
|
|||
|
damn sorry there such bad grammer and typo errors in my last post... guess u can tell i been working on my program for last 9 hours now!!! lol
|
|
#9
|
|||
|
|||
|
Quote:
The cool thing is that, once you know a way of doing things, lots of times you can find better ways (or at least ways that are more appealing to your sensibilities). Getting past that first block is the most important. Onward and upward! Regards, Dave |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Showing the "current" page | crystalattice | Web Design Forum | 5 | 27-Apr-2005 10:55 |
| Problem Showing Images !!!! | eRIC | MySQL / PHP Forum | 0 | 05-May-2004 22:33 |
| ClassView not showing my classes (VC++, namespace, headers) ?!?!? | djovanov | CPP / C++ Forum | 1 | 13-Jan-2004 04:54 |
| GIDZipTest now showing compression % | JdS | Learning Journal by J de Silva | 0 | 27-May-2003 22:14 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The