Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie needing help with output formatting

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am writing a program for my first programming class. The purpose of the assignment is to create a water estimater, which will calculate the volume of 4 rooms, then calc the amount of water needed to fill the rooms, then calc the cost to fill them. I got the program down just fine, but I am having troulbe getting my outputs into the correct decimal placement. instead of $1000.00 I just get 1000000 I appreciate any help that can be given, my code is written below.

Thanks again in advance for any help anyone can provide.

INPUT "Enter room name (DONE to quit) ", Nam
INPUT "Enter Length ", Length
INPUT "Enter Width ", RoomWidth
INPUT "Enter Height ", Height
INPUT "Enter Cost/Gallon ", GalCost

DO WHILE Nam <> EndNam
If Length <= 0 OR RoomWidth <= 0 OR Height <= 0 OR Galcost <= 0 THEN
PRINT &quot;ERROR - Low Value!&quot;
STOP
END IF
TotGal = Totgal + RoomGal
AvgVol = AvgVol + Vol
WaterCost = RoomGal * GalCost
TotWaterCost = TotWaterCost + WaterCost
Reccnt = RecCnt + 1
PRINT
PRINT
PRINT &quot;Room Name&quot;, &quot;Room Length&quot;, &quot;Room WIdth&quot;, &quot;Room Height&quot;
PRINT Nam, Length, RoomWidth, Height
PRINT
PRINT &quot;Room Volume &quot;, Vol
PRINT &quot;Cost Per Gallon &quot;; USING &quot;###.##&quot;; GalCost
PRINT &quot;Gallons &quot;; USING &quot;###.#&quot;; RoomGal
PRINT &quot;Water Cost &quot;; USING &quot;###.##&quot;; WaterCost
PRINT
PRINT
INPUT &quot;Enter Room Name&quot;, Nam
INPUT &quot;Enter length&quot;, Length
INPUT &quot;Enter Width&quot;, RoomWidth
INPUT &quot;Enter Height&quot;, Height
INPUT &quot;Enter Cost/Gallon&quot;, GalCost
LOOP
AvgVol = AvgVol / RecCnt

PRINT
PRINT
PRINT
PRINT &quot;Total Gallons required &quot;; TotGal
PRINT &quot;Total Water Cost &quot;; USING &quot;####.##&quot;; TotWaterCost
PRINT &quot;Average room Volume &quot;; USING &quot;####.###&quot;; AvgVol
END
 
If the decimal is always three places to the right, you could just divide the final answer by a thousand
 
Add a comma to the left of the decimal like so:

print using &quot;#######[red],[/red].##&quot;

That should do it. --MiggyD

It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Where do you calculate the volume of the room?
Where is the constant for calculating how many gallons / unit volume?

To MiggyD
Your example only inserts a comma in the display if the number actually warrants it. It will not make shamwop's program calculate properly. David Paulson

 
Earlier version required the print using to refer to one item only.
Try print &quot;description&quot;;:print using&quot;####.##&quot;variable and see if that doesn't resolve it. Ed Fair
unixstuff@juno.com
Any advice I give is my best judgement based on my interpretation of the facts you supply. Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.
 
dpaulson:
I misinturpted the original question. I presumed that what was needed was the $ and , in the product as was demonstrated. Now, after rereading it, I realized this question was for decimal placement (most likely alignment). I should have said to read the help files on PRINT USING or to convert the product to a string and then use the LEN() function for alignment.

Also indicated was: &quot;I got the program down just fine&quot;. Which indicated that his/her version of the actual code was working on their machine. So I didn't bother to run the code. Especially since it was an assignment. That's what the teacher is getting paid for and not I.

Anyway, thanks for pointing out my error.

shamwop:
Please read the first paragraph above.
--MiggyD

It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top