Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I'm working on a homework programs, but I'm a little stuck. I need to count pennies in a loop by the number of days entered, however the number of pennies needs to start at 1 and proceed to double each day. It also needs to total at the end.



Notes:
1. Written on VB 2010

2. The point of the homework is to use loops properly. The loop part does what its
suppose to, however I want the program to do what its suppose to do.

3. Don't worry about cosmetic suggestions, I always add them in/edit the .Writelines
at the end.


What I have tried:

The first one:

VB
Module Module1

    Sub Main()
        Dim Pennies As Double = 0.1
        Dim NumberOfDays As Integer = 0
        Dim InvalidInput As Integer = 0
        Dim Counter As Integer

        While InvalidInput <= 0
            Console.WriteLine("Enter number of days worked")
            NumberOfDays = Console.ReadLine
            If NumberOfDays >= 1 Then
                For Counter = 1 To NumberOfDays
                    Console.WriteLine("Day " & Counter & " you earned: $" & Pennies * 2)
                Next
            ElseIf NumberOfDays = InvalidInput Then
                Console.WriteLine("Invalid input")
            End If
        End While
    End Sub

End Module
Posted
Updated 24-Feb-16 9:25am
Comments
Kenneth Haugland 23-Feb-16 13:16pm    
Double each day? You would need to do something like this then:
Double TotalMoney = Pennies
for i as integer = 1 to NumberOfDays
TotalMoney * = 2
next
Maciej Los 23-Feb-16 13:19pm    
This is an answer.
Richard MacCutchan 23-Feb-16 13:32pm    
Don't use Double types for financial values, use integers. After all, you are only counting pennies.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

Advice:
Since
Quote:
the number of pennies needs to start at 1

you need to replace
VB.NET
Dim Pennies As Double = 0.1
by
VB.NET
Dim Pennies As Double = 1


You want to
Quote:
and proceed to double each day

you need
VB.NET
Pennies =Pennies * 2

in the loop

If you think
VB.NET
Console.WriteLine("Day " & Counter & " you earned: $" & Pennies * 2)

is the same as
VB.NET
Console.WriteLine("Day " & Counter & " you earned: $" & Pennies)
Pennies =Pennies * 2
, you have a lot of work and reading ahead of you.
 
Share this answer
 
v2
Comments
Member 12312671 23-Feb-16 14:59pm    
see when I multiply it by two, day one is still 2. it needs to start at one and double from there as you can see I multiplied pennies by two in this line with the same result in the code I posted.

Console.WriteLine("Day " & Counter & " you earned: $" & Pennies * 2)
Patrice T 23-Feb-16 15:10pm    
Multiply the pennies after displaying.
Member 12312671 23-Feb-16 15:21pm    
That did it TYVM man :) I appreciate it!
Member 12312671 23-Feb-16 15:27pm    
I forgot one more thing how can I get it to total all amounts at the end?
Member 12312671 23-Feb-16 15:28pm    
Or rather on each line
believe me your preaching to the quire, Google is my end all be all.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900