坚持我最后的作业问题。 [英] Stuck on my last homework problem.

查看:54
本文介绍了坚持我最后的作业问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在做家庭作业,但我有点卡住了。我需要按照输入的天数计算一个便士,但是便士的数量需要从1开始,然后每天加倍。它也需要在最后总计。







注意:

1。写在VB 2010上



2.作业的重点是正确使用循环。循环部分实现了它的b $ b假设,但是我希望程序能够做它想做的事。



3. Don'我担心化妆品的建议,我总是在最后添加/编辑.Writelines





我尝试过:



第一个:



 模块 Module1 

Sub Main()
Dim 便士作为 Double = 0 1
Dim NumberOfDays 作为 整数 = 0
Dim InvalidInput As I nteger = 0
Dim 计数器作为 整数

InvalidInput< = 0
Console.WriteLine( 输入天数工作
NumberOfDays = Console.ReadLine
如果 NumberOfDays> = 1 然后
对于计数器= 1 NumberOfDays
Console.WriteLine( Day&反制与反倾销 您获得的收入:$&便士* 2
下一步
ElseIf NumberOfDays = InvalidInput 然后
Console.WriteLine( 无效输入
结束 如果
结束
结束 Sub

结束 模块

解决方案

& Pennies * 2
下一步
ElseIf NumberOfDays = InvalidInput 然后
Console.WriteLine( 输入无效
结束 如果
结束 虽然
结束 Sub

结束 模块


您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到有一点它会停止你所期望的。

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]



建议:



引用:

需要从1开始的便士数量



你需要更换

  Dim 便士 As   Double  =  0  1  

by

  Dim 便士作为  Double  =  1  





你想

引用:

并且每天继续加倍



你需要

便士=便士*  2   



如果您认为

 Console.WriteLine(  Day&反制与反倾销您获得的 


&便士* 2





 Console.WriteLine(  Day& Counter&  


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:

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

解决方案

" & Pennies * 2) Next ElseIf NumberOfDays = InvalidInput Then Console.WriteLine("Invalid input") End If End While End Sub End Module


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

Dim Pennies As Double = 0.1

by

Dim Pennies As Double = 1



You want to

Quote:

and proceed to double each day


you need

Pennies =Pennies * 2


in the loop

If you think

Console.WriteLine("Day " & Counter & " you earned:


" & Pennies * 2)


is the same as

Console.WriteLine("Day " & Counter & " you earned:


这篇关于坚持我最后的作业问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆