Need help using Loop as Accumulator and variable storage
Author |
Message |
neozeak
|
Posted: Sun Apr 24, 2005 8:16 pm Post subject: Need help using Loop as Accumulator and variable storage |
|
|
I am writing a program for my compsci class that is basically supposed to recommend a product based upon the answers to two questions, while additionally asking other questions. The program must also provide a cost of the consultation, based upon number of questions answered. Store the final advice generated by the program as a variable. And offer the option to restart the consultation, while keeping the accumulator loop running to tack on additional costs to the consulation. If you are with me so far, you are probably better off than I. here is the code I have as of yet, if you can offer any advice as to how to adapt my code to perform the above results, I would greatly appreciate it.
code: | var name : string
var answer1, answer2, answer3, answer4, answer5, answer6 : string
var total, numberyes : int
numberyes := 0
put "Welcome to Comp 04 and More"
put " "
put "Please remember to press the ENTER key after each response."
put " "
put "Please enter your name."
get name:*
cls
put "Allow us to assist you in selecting the right service for you " , name , "."
put " "
put "Are you looking for help with either computers or mathematics? (y/n)"
get answer1
numberyes += 1
put " "
if answer1 = "y" then put "Then we are sure to have a package for you " , name , "."
else put "Those are the only services we offer here " , name , "."
end if
put " "
put name , " do you have a good attention span? (y/n)"
get answer2
numberyes += 1
if answer2 = "y" then put "We can do 2 hour long sessions once a week then " , name , "."
else put "Then we can do 1 hour sessions twice a week " , name , "."
end if
put " "
put "Did you bring something to write with " , name , "? (y/n)"
get answer3
numberyes += 1
if answer3 = "y" then put "Wonderful we can start right after this then!"
else put "I am sure we can find you something so we can get an early start!"
end if
put " "
put "So are you ready to get down to it and begin the tutoring? (y/n)"
get answer4
numberyes += 1
if answer4 = "y" then put "Wonderful! Let's start " , name , "!!"
else put "We will see if we can get you in the mood to learn then " , name , "!"
end if
delay (1800)
cls
put "So what can we tutor you in?"
put "Please enter a number for each corresponding choice."
put "1 Math only"
put "2 MS Office only"
put "3 Math and MS Office"
put "4 Java or C++"
get answer5
numberyes += 1
if answer5 = "1" then put "Calculus got you down " , name , "?"
elsif answer5 = "2" then put "Bill Gates can make some tricky programs, we can help though " , name, "!"
elsif answer5 = "3" then put "We have a dedicated staff willing to tutor you in both areas " , name, "."
elsif answer5 = "4" then put "You'll be a programming wizard in no time " , name , "!"
else put "That wasn't one of the choices " , name , "."
end if
delay (1800)
cls
put "After much thought, the package we recommend for " , name , " is..."
delay (1200)
put " "
if answer2 = "y" and answer5 = "1" then put "Package C, Two hours tutoring in the Math of your choice."
elsif answer2 = "y" and answer5 = "2" then put "Package B, Two hours tutoring in MS Office."
elsif answer2 = "y" and answer5 = "3" then put "Package A, Two hours tutoring of both MS Office and Math."
elsif answer2 = "y" and answer5 = "4" then put "Package D, Two hours tutoring in Java or C++ Programming."
elsif answer2 = "n" and answer5 = "1" then put "Package G, One hour tutoring in the Math of your choice."
elsif answer2 = "n" and answer5 = "2" then put "Package E, One hour tutoring in MS Office."
elsif answer2 = "n" and answer5 = "3" then put "Package F, One hour tutoring of both MS office and Math."
elsif answer2 = "n" and answer5 = "4" then put "Package H, One hour tutoring in Java or C++ Programming."
end if
put "Are you satisfied with our recommendation for you " , name , "? (y/n)"
get answer6
numberyes += 1
total := numberyes * (2)
if answer6 = "y" then put "Wonderful! Your total comes to $" , total , "."
end if |
I have until Wednesday to finish this. But I was trying to finish up a bit early...exams coming up and all. Any help is greatly appreciated.
EDIT: Code changed thanks to tokens advice
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Token
|
Posted: Sun Apr 24, 2005 9:05 pm Post subject: (No subject) |
|
|
i'm not exactly sure what it is you need, but why not have a variable and then add to it each time a question is answered that would give you the total number of questions answered and you can from that figure out the total cost... if this isnt it let us know, and could you please put your code inside code brackets [code ]put your code here[/code ] like that w/o the spaces...
code: |
var name : string
var answer1, answer2, answer3, answer4, answer5, answer6 : string
var total, totalquest : int :=0 %% := sets it to zero that way when you take += or the value of it plus ... it dosent crash
put "Welcome to Comp 04 and More"
put " "
put "Please remember to press the ENTER key after each response."
put " "
put "Please enter your name."
get name:*
cls
put "Allow us to assist you in selecting the right service for you " , name , "."
put " "
put "Are you looking for help with either computers or mathematics? (y/n)"
get answer1
totalquest += 1
put " "
if answer1 = "y" then put "Then we are sure to have a package for you " , name , "."
else put "Those are the only services we offer here " , name , "."
end if
put " "
put name , " do you have a good attention span? (y/n)"
totalquest += 1
get answer2
if answer2 = "y" then put "We can do 2 hour long sessions once a week then " , name , "."
else put "Then we can do 1 hour sessions twice a week " , name , "."
end if
put " "
put "Did you bring something to write with " , name , "? (y/n)"
get answer3
totalquest += 1
if answer3 = "y" then put "Wonderful we can start right after this then!"
else put "I am sure we can find you something so we can get an early start!"
end if
put " "
put "So are you ready to get down to it and begin the tutoring? (y/n)"
get answer4
totalquest += 1
if answer4 = "y" then put "Wonderful! Let's start " , name , "!!"
else put "We will see if we can get you in the mood to learn then " , name , "!"
end if
delay (1800)
cls
put "So what can we tutor you in?"
put "Please enter a number for each corresponding choice."
put "1 Math only"
put "2 MS Office only"
put "3 Math and MS Office"
put "4 Java or C++"
get answer5
totalquest += 1
if answer5 = "1" then put "Calculus got you down " , name , "?"
elsif answer5 = "2" then put "Bill Gates can make some tricky programs, we can help though " , name, "!"
elsif answer5 = "3" then put "We have a dedicated staff willing to tutor you in both areas " , name, "."
elsif answer5 = "4" then put "You'll be a programming wizard in no time " , name , "!"
else put "That wasn't one of the choices " , name , "."
end if
delay (1800)
cls
put "After much thought, the package we recommend for " , name , " is..."
delay (1200)
put " "
if answer2 = "y" and answer5 = "1" then put "Package C, Two hours tutoring in the Math of your choice."
elsif answer2 = "y" and answer5 = "2" then put "Package B, Two hours tutoring in MS Office."
elsif answer2 = "y" and answer5 = "3" then put "Package A, Two hours tutoring of both MS Office and Math."
elsif answer2 = "y" and answer5 = "4" then put "Package D, Two hours tutoring in Java or C++ Programming."
elsif answer2 = "n" and answer5 = "1" then put "Package G, One hour tutoring in the Math of your choice."
elsif answer2 = "n" and answer5 = "2" then put "Package E, One hour tutoring in MS Office."
elsif answer2 = "n" and answer5 = "3" then put "Package F, One hour tutoring of both MS office and Math."
elsif answer2 = "n" and answer5 = "4" then put "Package H, One hour tutoring in Java or C++ Programming."
end if
put "Are you satisfied with our recommendation for you " , name , "? (y/n)"
get answer6
totalquest += 1
total := totalquest * (Price here)
if answer6 = "y" then put "Wonderful! Your total comes to " , total
end if |
|
|
|
|
|
|
neozeak
|
Posted: Sun Apr 24, 2005 9:42 pm Post subject: (No subject) |
|
|
thanks a lot for your help, and I am sorry about not putting the code correctly. That helps with the accumulator problem I think, but I am supposed to be able to give them the option to start over after the end if they are not happy with the advice given. How would one go about doing that
|
|
|
|
|
|
Token
|
Posted: Mon Apr 25, 2005 6:18 am Post subject: (No subject) |
|
|
well what you could do is make the entire program inside 2 loops, and then after each question ask start again? and if the person says yes then exit the first loop which would then take you to the seccond, causing it to start over again, like this
code: |
var name : string
var answer1, answer2, answer3, answer4, answer5, answer6,restart : string
var total, totalquest : int :=0 %% := sets it to zero that way when you take += or the value of it plus ... it dosent crash
procedure restartquest
put "\nstart over? (y/n) "..
get restart
if restart = "y" or restart = "Y" then
exit
end if
end restartquest
loop
loop
put "Welcome to Comp 04 and More"
put " "
put "Please remember to press the ENTER key after each response."
put " "
put "Please enter your name."
get name:*
cls
put "Allow us to assist you in selecting the right service for you " , name , "."
put " "
put "Are you looking for help with either computers or mathematics? (y/n)"
get answer1
totalquest += 1
put " "
if answer1 = "y" then put "Then we are sure to have a package for you " , name , "."
else put "Those are the only services we offer here " , name , "."
end if
restartquest
put " "
put name , " do you have a good attention span? (y/n)"
totalquest += 1
get answer2
if answer2 = "y" then put "We can do 2 hour long sessions once a week then " , name , "."
else put "Then we can do 1 hour sessions twice a week " , name , "."
end if
restartquest
put " "
put "Did you bring something to write with " , name , "? (y/n)"
get answer3
totalquest += 1
if answer3 = "y" then put "Wonderful we can start right after this then!"
else put "I am sure we can find you something so we can get an early start!"
end if
restartquest
put " "
put "So are you ready to get down to it and begin the tutoring? (y/n)"
get answer4
totalquest += 1
if answer4 = "y" then put "Wonderful! Let's start " , name , "!!"
else put "We will see if we can get you in the mood to learn then " , name , "!"
end if
delay (1800)
cls
restartquest
put "So what can we tutor you in?"
put "Please enter a number for each corresponding choice."
put "1 Math only"
put "2 MS Office only"
put "3 Math and MS Office"
put "4 Java or C++"
get answer5
totalquest += 1
if answer5 = "1" then put "Calculus got you down " , name , "?"
elsif answer5 = "2" then put "Bill Gates can make some tricky programs, we can help though " , name, "!"
elsif answer5 = "3" then put "We have a dedicated staff willing to tutor you in both areas " , name, "."
elsif answer5 = "4" then put "You'll be a programming wizard in no time " , name , "!"
else put "That wasn't one of the choices " , name , "."
end if
delay (1800)
cls
put "After much thought, the package we recommend for " , name , " is..."
delay (1200)
put " "
if answer2 = "y" and answer5 = "1" then put "Package C, Two hours tutoring in the Math of your choice."
elsif answer2 = "y" and answer5 = "2" then put "Package B, Two hours tutoring in MS Office."
elsif answer2 = "y" and answer5 = "3" then put "Package A, Two hours tutoring of both MS Office and Math."
elsif answer2 = "y" and answer5 = "4" then put "Package D, Two hours tutoring in Java or C++ Programming."
elsif answer2 = "n" and answer5 = "1" then put "Package G, One hour tutoring in the Math of your choice."
elsif answer2 = "n" and answer5 = "2" then put "Package E, One hour tutoring in MS Office."
elsif answer2 = "n" and answer5 = "3" then put "Package F, One hour tutoring of both MS office and Math."
elsif answer2 = "n" and answer5 = "4" then put "Package H, One hour tutoring in Java or C++ Programming."
end if
put "Are you satisfied with our recommendation for you " , name , "? (y/n)"
get answer6
totalquest += 1
total := totalquest * (Price here)
if answer6 = "y" then put "Wonderful! Your total comes to " , total
end if
end loop
end loop
|
i could only do the first one because i g2g i'll do the rest from school, cya
|
|
|
|
|
|
jamonathin
|
Posted: Mon Apr 25, 2005 8:54 am Post subject: (No subject) |
|
|
lol, maybe next time you guys should just upload it from a .t file.
|
|
|
|
|
|
Token
|
Posted: Mon Apr 25, 2005 10:47 am Post subject: (No subject) |
|
|
jamonathin: in heinsight, that seems like a good idea lol but i thaught it would be over in one post... gues not lol oh well... hope that helps.
|
|
|
|
|
|
jamonathin
|
Posted: Mon Apr 25, 2005 11:20 am Post subject: (No subject) |
|
|
Yesh, it helps very much.
|
|
|
|
|
|
neozeak
|
Posted: Mon Apr 25, 2005 2:29 pm Post subject: (No subject) |
|
|
I am only supposed to ask them to restart the program following the last question, additionally the code you posted does not restart the loop upon answering no, is that because you didn't have time to finish?
Description: |
|
Download |
Filename: |
lab-08-advice-neozeak.t |
Filesize: |
3.51 KB |
Downloaded: |
93 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Token
|
Posted: Mon Apr 25, 2005 2:56 pm Post subject: (No subject) |
|
|
Here, try this, i had the right idea, crappy method.
Description: |
|
Download |
Filename: |
lab-08-advice-neozeak[1].t |
Filesize: |
3.61 KB |
Downloaded: |
97 Time(s) |
|
|
|
|
|
|
neozeak
|
Posted: Mon Apr 25, 2005 3:42 pm Post subject: (No subject) |
|
|
I basically just came to the same conclusion finally, I have been messing with the code for like an hour. So all my problems are solved minus one.
How do I save the advice given as a variable? I have looked for a store function or something along those lines and cannot find anything.
|
|
|
|
|
|
Token
|
Posted: Mon Apr 25, 2005 4:44 pm Post subject: (No subject) |
|
|
okay well you could save it into a string variable
code: |
advice:="Package C, Two hours tutoring in the Math of your choice." |
|
|
|
|
|
|
neozeak
|
Posted: Mon Apr 25, 2005 6:20 pm Post subject: (No subject) |
|
|
this is what it says in the rubric for my project:
give some final advice about what products/services to buy based on atleast two answers, storing that final advice as a variable. That to me means that in each particular case i am supposed to store it as a variable after it has been given, as the advice given does vary based upon the responses of the individual. Is there a way to do that?
|
|
|
|
|
|
Token
|
Posted: Mon Apr 25, 2005 7:17 pm Post subject: (No subject) |
|
|
mm to me i see this as saying to store the variable that you are sending to this person specifically as per their questions.
|
|
|
|
|
|
|
|