Jump to content

Homework Help please

- - - - -

  • Please log in to reply
8 replies to this topic

#1
Ryanw327

Ryanw327

    Newbie

  • Members
  • PipPip
  • 13 posts
Problem.

At one college, the tuition for a full-time student is $6,000 per semester. It has been announced that the tuition will increase by 2% each year for the next 5 years. Design a program with a loop that displays the projected semesters tuition amount for the next five years.


//Declare Variables 

Declare Real tuitionIncrease, semesters, count, tuitionCost, runningTotal

Constant Real tuition = 6000

//Assign values

tuitionIncrease = 1.01  // 1% tuition increase per semester 

semesters =  10 // 10 semesters in 2 years 

tuitionCost = tuition*tuitionIncrease

runningTotal = 0


Display “The tuition will increase 2% per year” 


For count = 1 To semsters 

runningTotal = runningTotal + tuitionCost

	Display “semester”, count, Tab, runningTotal

End For // End of For loop 



I don't think this is even in the right ballpark of correct. considering the tuition cost needs to be compounding. Any help would be appreciated.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
tuitionIncrease = 1.02

you need tuition=tuition*tuitionIncrease inside your for loop.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Ryanw327

Ryanw327

    Newbie

  • Members
  • PipPip
  • 13 posts
tuitionIncrease = 1.02 would increase the tuition 4% per year, am I correct?

tuition = tuition*tuitionIncrease does the compounding tuition, but should I take out the Constant tuition = 6000?

Thankyou

//Declare Variables

Declare Real tuitionIncrease, semesters, count, 

Constant Real TUITION = 6000

//Assign values

tuitionIncrease = 1.01  // 1% tuition increase per semester 

semesters =  10 // 10 semesters in 2 years 


Display “The tuition will increase 2% per year” 

For count = 1 To semsters 

	TUITION =TUITION *tuitionIncrease

	Display “semester”, count, Tab, TUITION 

End For // End of For loop



#4
Ryanw327

Ryanw327

    Newbie

  • Members
  • PipPip
  • 13 posts
I think I got this one figured out correctly but I might still have a mistake.

Design a program with a loop that lets the user enter a series of numbers. The user should enter -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered.


Main()

//Declare local variables 

Declare Real number, smallestNumber, largestNumber

//Assign default value 

number = 0

Do 

	Display “Please enter a number. Enter -99 to quit!”

	input number

	Call largeorSmall(number)

Until number == “-99”

Display “The largest number is”, largestNumber

Display “The smallest number is”, smallestNumber

End // end of Main


largeorSmall(Real ref largestNumber, smallestNumber)

Declare Real largestNumber = 0 

Declare Real smallestNumber = 0 


if number >=largestNumber	

	largestnumber = number 

else 

	if number<=smallestNumber

		smallestNumber = number 

	end if

end if // end of if 

end Module // end of large or small 



My thoughts on why this is wrong, I'm not sure if I am passing the variables largestNumber & smallestNumber correctly?

Thank you again I know you have better things to do then to help me with my homework :cool:

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Are you assuming your variables are static between calls of your function? That would not normally be the case. Also, the first time the user inputs the data, you need to set both largest and smallest to that value.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
Ryanw327

Ryanw327

    Newbie

  • Members
  • PipPip
  • 13 posts
I'm not assuming my variables are static. I'm not sure how I am supposed to pass those variables (largestNumber & smallestNumber) back to main so I can display them after the loop.
so in my module I should
largestNumber = number
smallestNumber = number
That makes sense, if the user only entered one number it would be both the largest and smallest number.

How do I get largeestNumber and smallestNumber out of my function?

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Is there a reason you're using a function for that?

Also, you may want to use to functions: min(a,b) and max(a,b) to assign to smallest a largest, respectively.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
Ryanw327

Ryanw327

    Newbie

  • Members
  • PipPip
  • 13 posts
I could just put the if statement in the loop that does make things easier. I think it looks better to use the function, lol.

if I were to use min(a,b) max(a,b) I think there might be a conflict between smallestNumber and largestNumber.

#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
smallest = min(smallest, input)
largest = max(largest, input)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users