Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Looping/Valid/Invalid Input...
Author Message
Hunter007

Posted: Wed Jan 14, 2004 6:27 pm   Post subject: Looping/Valid/Invalid Input...

I've been working on a lot of different progs at the same time (school) and I seem to have gotten confused. This program here is supposed to calculate any amount of pizzas(any size) with any number of toppings. No tax is needed. I think it calculates one order at a time now. I;m posting my code, hoping someone can help me out.

 code: const smallpiz : real := 6.00 const largepiz : real := 8.00 const smalltop : real := 0.75 const largetop : real := 1.25 var pizza : string var numtop : real var cost : real := 0 var topcost : real:=0 var reply : string (1) var totalcost : real:=0 var subtotal : real:=0 loop     put "Press any key to continue or 'q' to quit..."     put ""     getch (reply)     exit when reply = "q" or reply = "Q"     loop            put "**When finished type in 'none' as pizza size.**"            put""            put "Small or large pizza? " ..            get pizza            put ""            if pizza = "none" then                   exit            end if            put "Number of toppings: " ..            get numtop            if pizza = "small" then                   topcost := numtop * smalltop                   cost := smallpiz + topcost            elsif pizza = "large" then                   topcost := numtop * largetop                   cost := largepiz + topcost            end if            cls     end loop     totalcost := totalcost + cost     put "The cost of your pizza is \$", totalcost : 2 : 2, "."     delay (2500)     cls     cost := 0     topcost := 0     totalcost:=0 end loop

poly

Posted: Wed Jan 14, 2004 7:47 pm   Post subject: (No subject)

I see what your error is and its a very simple one, just have to move a line up. Here I posted the code below, you can see what I moved to fix this error, I made comment:

 code: const smallpiz : real := 6.00 const largepiz : real := 8.00 const smalltop : real := 0.75 const largetop : real := 1.25 var pizza : string var numtop : real var cost : real := 0 var topcost : real := 0 var reply : string (1) var totalcost : real := 0 var subtotal : real := 0 loop     put "Press any key to continue or 'q' to quit..."     put ""     getch (reply)     exit when reply = "q" or reply = "Q"     loop         put "**When finished type in 'none' as pizza size.**"         put ""         put "Small or large pizza? " ..         get pizza         put ""         if pizza = "none" then             exit         end if         put "Number of toppings: " ..         get numtop         if pizza = "small" then             topcost := numtop * smalltop             cost := smallpiz + topcost         elsif pizza = "large" then             topcost := numtop * largetop             cost := largepiz + topcost         end if                 totalcost := totalcost + cost   % I JUST MOVED THIS LINE BEFORE THE CLS         cls     end loop     put "The cost of your pizza is \$", totalcost : 2 : 2, "."     delay (2500)     cls     cost := 0     topcost := 0     totalcost := 0 end loop

the formula " totalcost := totalcost + cost " was after the CLS, so when it was time to tally it all up the CLS would just clear all vars. So I just moved it above the CLS and presto!
Thuged_Out_G

Posted: Thu Jan 15, 2004 10:36 am   Post subject: (No subject)

cls only clears the screen, it doesnt clear variables

Posted: Thu Jan 15, 2004 1:47 pm   Post subject: (No subject)

No, no, no...poly is right, and he wasnt clearing variables.
Hunter007 wrote:

cls
end loop

totalcost := totalcost + cost

poly wrote:

totalcost := totalcost + cost % I JUST MOVED THIS LINE BEFORE THE CLS
cls
end loop

See, poly moved the totalcost calculator from outside the loop, to inside above the cls...he wasnt try to stop cls from clearing variables or anything.
Thuged_Out_G

Posted: Thu Jan 15, 2004 2:52 pm   Post subject: (No subject)

thats just the mesasge i got from
poly wrote:

CLS would just clear all vars
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: