Question:

I have a quick question for a programming exercise in pseudocode.?

by  |  earlier

0 LIKES UnLike

Here's my program:

Display “Enter the amount of the purchase.”

Input amount

Set state = amount * .04

Set county = amount * .02

Set tax = state + county

Set total = amount + tax

Display “The amount of the purchase is $”, amount

Display “The state sales tax is $”, state

Display “The county sales tax is $”, county

Display “The total sales tax is $”, tax

Display “The total of the sale is $”, total

My question is whether or not I need to set amount equal to 0 at the beginning.

 Tags:

   Report

3 ANSWERS


  1. I wouldnt think you would need to. Because its not like your performing arithmatic on the amount variable anyway, your assigning it a value with the input.


  2. i wouldn't think so for your pseudocode. since your pseudocode fills 'amount' with a new value initially. when you code it (however you plan on coding it) you just want to be aware you may need to initialize 'amount' to a value first.

  3. It is always a good idea to initialize your variables.. say your user cancels the input.. what would be amount's value for the rest of the code??

    If amount can be say 0-100, I would initialize amount to an illegal value such as -1 !

    Why? So that if your user cancels the input, you will know straight away :) Also, check that amount value is in your expected range right after the input.. what if I input "a" in response to your query for amount? exception!

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.