• 0

Need help with some pseudocode


Question

I need help with some homework from my intro to programming class. Here's what I have so far  

Design a flow chart or pseudocode for a program for Hunterville College that will display the projected tuition rate for the next 10 years. 
The current tuition is $15,000 per year and will increase by 4 percent next year, and every year after that the tuition increase is expected to be 0.5 more (thus 4%, then 4.5%, then 5%, etc).

The output should be:

 Year      Tuition

   1       15,600.00

   2       16,302.00

   3       17,117.10

   4       18,058.54

   5       19,142.05

   6       20,386.29

   7       21,813.33

   8       23,449.33

   9       25,325.27

   10      27,477.92
   
                 HERES WHAT I HAVE SO FAR 
//Lab 5 
//Show the increase in tuition for Hunterville College 
//It will increase by 4% the first year and an added 0.5% each following year 

Begin Main module 

Declare Integer original_tuition
Declare Integer year
Declare Real tuitionA-J

	Display "Year    Tuition" 

Set year = 0 
Set original_tuition = 6000
While year = 1 {
tuitionA = original_tuition + 0.04*original_tuition
Set mArray[1] = tuitionA   
	Display "1      ;tuitionA"tuitionA 
End While	

While year = 2
tuitionB = = tuitionA + 0.045tuitionA 
Set mArray[2] = tuitionB
	Display "2      ;tuirionB"tuitionB 

 

Now I could just continue it like this, but is there any way i can make it into a loop? I feel that would be more efficient. Thank you 

-crisP  

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

http://codepen.io/mur/pen/9dfc971f15e9ef98a70bb7f970712417/left/

I ended up doing this, didn't really like the idea of "doing it for you" but it will give you a bit of a sense of how the information gets processed. I used a loop (naturally) as you mentioned because it was the best way to do it, you can modify all of the values at the top to get different outcomes as well.

Link to comment
Share on other sites

  • 0

http://codepen.io/mur/pen/9dfc971f15e9ef98a70bb7f970712417/left/

I ended up doing this, didn't really like the idea of "doing it for you" but it will give you a bit of a sense of how the information gets processed. I used a loop (naturally) as you mentioned because it was the best way to do it, you can modify all of the values at the top to get different outcomes as well.

 

Holy overkill, Batman!

t = 15400

y = 1

i = 1.04

print y,  t

while (y < 10)

{

   i=i+.005

     t=t * i

    y=y+1

    print y,t

}

thats pseusdocode, the smallest sketch that communicates the algorithm

neowin scrolled the increase line far right so it wasn't in my window!

"

tuition increase is expected to be 0.5 more (thus 4%, then 4.5%, then 5%, etc).

"

now fixed lol

OP: download code that intrigues you from GitHub. and hit khan academy - there is no way a loop should be a puzzle to you - khan has a cool section where you can copy other peoples javascript mini-games and then hack on it - but read lots of other people's code

And maybe read my comments here:

www.neowin.net/forum/topic/1273312-learning-to-code-best-options-issues/

 

Edited by DevTech
off-by-one error lol
Link to comment
Share on other sites

  • 0

Holy overkill, Batman!

It took me under a minute to do that, and provides a working example in it's simplest form, not overkill at all. It's also only 23 lines factoring in everything involved.

Link to comment
Share on other sites

  • 0

It took me under a minute to do that, and provides a working example in it's simplest form, not overkill at all. It's also only 23 lines factoring in everything involved.

 

yeah but it is real working code, not pseudo

i fear we both went way too far on a homework thingy

( i think i will decline from responding to these in the future, too much like eating candy!)

Link to comment
Share on other sites

  • 0

yeah but it is real working code, not pseudo

i fear we both went way too far on a homework thingy

I'm working towards a PhD so it's what I naturally do :/

That said, your method starts are 15,400 which I'm not sure why (considering year one is $15,600 based on the OP) there's also no factoring in of the initial 4% increase, you've just applied it yourself initially which in a real world application isn't necessarily wrong, but for the assignment isn't answer what is asked.

Link to comment
Share on other sites

  • 0

I'm working towards a PhD so it's what I naturally do :/

That said, your method starts are 15,400 which I'm not sure why (considering year one is $15,600 based on the OP) there's also no factoring in of the initial 4% increase, you've just applied it yourself initially which in a real world application isn't necessarily wrong, but for the assignment isn't answer what is asked.

15400 should be 15600 - typo

since it was pseudo code which is more like a flowchart, i thought there would be more clarity to start at 15600

depends on one definition of pseudocode but for me it's "paper napkin sketch" and doesn't even have to be completely correct as long as it jumpstarts the code

what phd you doing? and what's your research topic gonna be :)

 

Link to comment
Share on other sites

  • 0

15400 should be 15600 - typo

since it was pseudo code which is more like a flowchart, i thought there would be more clarity to start at 15600

depends on one definition of pseudocode but for me it's "paper napkin sketch" and doesn't even have to be completely correct as long as it jumpstarts the code

what phd you doing? and what's your research topic gonna be :)

That's fair, I prepare pseudo code mentally all the time when not at my laptop or office desktop. But to me it would be to clearly define what the process would be and segment out all variables for potential future modifications - since nothing is usually ever safe to be set in stone, and naturally robust options are far better in forward thinking).

PhD is in Human-centered Design and Engineering and I haven't decided on a research topic, there's 3 I am currently battling myself on, one will be a research topic while the other two become elongated blog posts (if I ever have time to get my blog site done), but I haven't selected which one I like best yet.

Link to comment
Share on other sites

This topic is now closed to further replies.