我的作业能帮忙吗?这是我到目前为止: [英] Can i have assistance with my homework? here is what i have so far:

查看:73
本文介绍了我的作业能帮忙吗?这是我到目前为止:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然是编程方面的新手,而且我正处于家庭工作问题的中间。我能够写出程序的基础,但它按照我想要的方式运行。它需要做的是显示输入两个原色的结果颜色,如果输入了其他任何内容则显示错误,但它只是直接跳到错误。



5.颜色混合器

红色,蓝色和黄色被称为原色,因为它们不能通过混合其他颜色来制作。当你混合两种原色时,你会得到一种二次色,如下所示:

●当你混合红色和蓝色时,你会变成紫色。

●当你混合红色和黄色时,你会变成橙色。

●当你混合蓝色和黄色时,你会变绿。

设计一个程序,提示用户输入要混合的两种主要颜色的名称。如果用户输入红色,蓝色或黄色以外的任何内容,程序应显示错误消息。否则,程序应该显示结果的辅助颜色的名称。



我尝试过:



Hi I'm still fairly new to programming and I am in the middle of a home work question Though I bricked at this point. I was able to write out the base of the program, however it's functioning the way I want it to. What it needs to do is display the result color of entering two primaries and display an error if anything else has been entered, however it just jumps straight to the error.

5. Color Mixer
The colors red, blue, and yellow are known as the primary colors because they cannot be made by mixing other colors. When you mix two primary colors, you get a secondary color, as shown here:
● When you mix red and blue, you get purple.
● When you mix red and yellow, you get orange.
● When you mix blue and yellow, you get green.
Design a program that prompts the user to enter the names of two primary colors to mix. If the user enters anything other than "red," "blue," or "yellow," the program should display an error message. Otherwise, the program should display the name of the secondary color that results.

What I have tried:

Module Module1

    Sub Main()
        'Declare variables
        Dim Red As String
        Dim Blue As String
        Dim Yellow As String
        Dim Color1 As String
        Dim Color2 As String

        'User input
        Console.WriteLine("Input 2 colors Choices one at a time from Red, Blue, or Yellow.")
        Color1 = Console.ReadLine
        Color2 = Console.ReadLine
        If Color1 = Red And Color2 = Blue Then
            Console.WriteLine("Purple")
        Else If Color1 = Red And Color2 = Yellow Then
            Console.WriteLine("Orange")
        ElseIf Color1 = Yellow And Color2 = Blue Then
            Console.WriteLine("Green")
        Else
            Console.WriteLine("Error: Invalid input")
        End If
        Console.WriteLine("Press Enter to quit.")
        Console.ReadKey(ConsoleKey.Enter)

    End Sub

End Module





附注:

(*)I还尝试不制作原色变量,但是它导致了语法错误。

(*)我们在课堂上使用的语言是VB。



Side notes:
(*)I've also tried not making the primary colors variables, however it caused a syntax error.
(*)The language we use in class is VB.

推荐答案

好吧 - 因为它的作业,我会给你很好的提示但是没有透露一切。



想象一下,我告诉你:我有一个名为 X 的整数变量。 X + 5的结果是什么?。你的回答是什么?由于类似的问题你的代码无法工作。



当你解决了这是另一个问题,虽然它更具概念性:两个输入有多少种颜色组合,每种都有3个选项?在得出输入无效的结论之前,你的代码只涵盖了少数这些组合。



如果你到目前为止工作并想要一个小小的挑战,请留下答复,我会给你一个小小的提示,告诉你如何以更优雅的方式做到这一切祝你好运。



祝你好运!
Alright - as it's homework, I will give you good hints but not reveal everything.

Imagine I tell you this: "I have an integer variable named X. What is the result of X + 5 ?". What will be your response? Your code can't work because of an analogous problem.

When you've solved this, there's another problem, though it's more conceptual: How many color combinations can there be for two inputs with 3 options each? Your code only covers a small number of these combinations before jumping to the conclusion that the input was invalid.

If you got this working so far and would like a small challenge, leave a reply and I'll give you a small hint on how you could do all this in a more elegant way.

Good luck!


你还没有为红色,蓝色或黄色变量赋值,所以输入颜色将永远不会匹配,因此您将看到错误消息。



您需要学习如何调试代码 - 请查看此CodeProject文章:

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]
You haven't assigned a value to the variables Red, Blue, or Yellow so the input colour will never match and so you will drop through to your error message.

You need to learn how to debug your code - have a look at this CodeProject article:
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]


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



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

在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 [ ^ ]
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[^]


这篇关于我的作业能帮忙吗?这是我到目前为止:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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