How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Tech_Ben Your Own Question
Tech_Ben
Tech_Ben, Computer Software Engineer
Category: Programming
Satisfied Customers: 1773
Experience:  10 years professional experience in Java, C++, Visual Basic, .NET, DB2, Oracle, SQL Server
8287049
Type Your Programming Question Here...
Tech_Ben is online now
A new question is answered every 9 seconds

I currently taking a basic programming class (on-line) the

This answer was rated:

I currently taking a basic programming class (on-line) the text we are using is Farrell Programming logic & design. Chapter 4 & 5 assignments are driving me crazy. Does anyone have really good on-line links that could help me better understand?
HiCustomer

Thank you for the question. Are the assignments short enough to type out here? Please let me know the details of the assignment and I will be happy to assist further. Thanks again,
Customer: replied 8 years ago.

Thanks - Ben

According to my teacher it is basic logic! But she has sent my two assignements back to me and I'm just not getting this.

I'm currently reading about loops. She would like a program that accepts a candy name, price per pound, and number of pounds sold in the average month, and displays the item's data only if it sell more than 2000 pounds.

He is what I wrote...

start

Candy_Record()

string Line1 = “candy name”

string Line2 = “price per pound”

string Line3 = “number of pounds sold per month”

get Candy_Record()

if lbssold > 2000 print the record

get the next record

endif

stop



Thanks.

James
Hi James,

The reason it was sent back to you is likely because you are not using a loop anywhere in your code. The "IF" statement is used to test a condition, but there is nothing performing a loop. In your case, if the condition is met, it performs the operation after your statement. Even though you are saying "Get the next record" in your if statement, it is not a true loop. You can do something like this:

Candy_Record()
Declare String name
Declare String price
Declare String lb_sold

Print "Enter candy name: "
Input name

Print "Enter the price per pound: "
Input price

Print "Enter number of pounds sold per month: "
Input lb_sold

get Candy_Record()
while lb_sold > 2000
Print name + " sold more than 2000 lbs this month."
End While
stop
Tech_Ben and other Programming Specialists are ready to help you
Customer: replied 8 years ago.

Can I ask you about my second assignment?
Yes, please do. I am however stepping out for about a half hour, but will be happy to help when I get back. Or you can create a new question and request me. Thanks again!
Customer: replied 8 years ago.
Loop 2

Start

a=3, b=4, c=8

Is c greater than 6 (Yes)



Perform changeBAndC()

5 = 4 + 1

7 = 8 - 1

a=3, b=5, c=7

Does a = 2 (No)



Does c = 10 (No)



Perform changeBAndC()

6 = 5 + 1

6 = 7 - 1

a=3, b=6, c=6

Return







Loop 1

Start

a=2, b=4, c=10

Is c greater than 6 (Yes)

perform changeBAndC()

5= 4 + 1

9= 10 -1

a=2, b=5, c=9

Does a = 2 (Yes)

perform changeAAndB()

3 = 2 + 1

4 = 5 - 1

a=3, b=3, c=9

Does c = 10 (No)

Perform changeBAndC()

4 = 3 + 1

8 = 9 - 1

a=3, b=4, c=8





Return

Loop 4

Start

a=3, b=6, c=6

c greater than 6



No



a = 2



No



C = 10



No



Print a, b, c



Stop

What are the values of variables a, b, and c after each run of each loop. Show why the loop is running,what happens during each run of the loops and what the variable values are at the end of EACH RUN of the loop. Submit in a MS Word doc.

start
a = 2
b = 4
c = 10
while c > 6
perform changeBAndC()
endwhile
if a = 2 then
perform changeAAndB()
endif
if c = 10 then
perform changeAAndB()
else
perform changeBAndC()
endif
print a, b, c
stop

changeBAndC()
b = b + 1
C = C - 1
return
changeAAndB()
a = a + 1
b = B - 1
return





















Loop 3

Start

a=3, b=6, c=6

Is c greater than 6 (No)



Does a = 2 (No)



Does c = 10 (No)



perform changeBAndC()

7 = 6 + 1

5 = 4 - 1

a=3, b=7, c=5





print a, b, c



stop






















My teacher said: James, we need to redo this. You logic is off - the first loop continues to process until C is not > 6, only then does the program fall to the second loop., etc.



Hi James,

Can you post just the assignment without the code? Is there code supplied and questions about it, and then an assignment to write some code? You will never need to state that 5 = 5 in your code (ie - where you have 5 = 4 + 1), so it is not necessary to write that anywhere. If you can post just the assignment it will be easier for me to distinguish what the question/assignment is, from the code you have written. Thanks again!
Customer: replied 8 years ago.
What are the values of variables a, b, and c after each run of each loop. Show why the loop is running,what happens during each run of the loops and what the variable values are at the end of EACH RUN of the loop. Submit in a MS Word doc.

start
a = 2
b = 4
c = 10
while c > 6
perform changeBAndC()
endwhile
if a = 2 then
perform changeAAndB()
endif
if c = 10 then
perform changeAAndB()
else
perform changeBAndC()
endif
print a, b, c
stop

changeBAndC()
b = b + 1
C = C - 1
return
changeAAndB()
a = a + 1
b = B - 1
return
I've attached the solution as a MS Word doc, since that seems to be part of the assignment.

Here it is. Let me know if you have any questions. Thanks again,
Tech_Ben and other Programming Specialists are ready to help you

Related Programming Questions