如何提示用户从数组中选择2个元素并将它们组合起来? [英] How do I prompt a user to select 2 elements from an array and combine them?

查看:112
本文介绍了如何提示用户从数组中选择2个元素并将它们组合起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jobArray []有5个工作。每份工作都包含说明,完成工作的时间和每份工作的每小时工资。



我必须提示用户输入他们想要合并的2个工作。合并后的作业将具有组合描述,hoursToComplete和基于所选2个作业的计算小时工资。



我不确定如何从这里获取用户输入并将其与阵列中的元素匹配并组合它。



下面是我的代码和combineJobs()模块,我有用户输入他们想要合并的2个工作。

I have a jobArray[] with 5 jobs. Each job contains a description, hours to complete the job and hourly pay for each job.

I have to prompt the user to input 2 jobs they would like to combine. The combined job will have the combined description, hoursToComplete and a calculated hourly pay based on the 2 jobs selected.

I'm unsure how to go from here in regards to taking the users input and matching it to the element in the array and combining it.

Below is my code and the combineJobs() module is where I'm having the user input which 2 jobs they would like to combine.

//combining jobs
public static void CombineJobs()
{
    Console.WriteLine("Which 2 jobs would you like to combine?");

    //printing out array elements
    for (int i = 0; i < jobArray.Length; i++)
    {
        string option;
        Console.WriteLine("Job " + i);
    }

}


}





在combineJobs()模块中,我打印出数组索引供用户选择。这是我的第二堂课的一部分



In the combineJobs() module I print out the array indexes for the user to choose from. Here is part of my second class also

class Job : IComparable<Job>
{
public string Description { get; set; }

public int hoursToComplete { get; set; }

public double hourlyRate { get; set; }

public double totalFee { get; set; }

public Job(string description,
            int hours,
            double hourRate,
            double fee)
{
    Description = description;
    hoursToComplete = hoursToComplete;
    hourlyRate = hourlyRate;
    totalFee = totalFee;

}

public Job()
{
    // TODO: Complete member initialization
}

public static Job operator +(Job first, Job second)
{
    String newDescription = first.Description + " and " + second.Description;
    int newHoursToComplete = first.hoursToComplete + second.hoursToComplete;
    double newHourlyRate = first.hourlyRate + second.hourlyRate / 2;
    double newTotalFee = first.totalFee + second.totalFee;
    return (new Job(newDescription, newHoursToComplete, newHourlyRate, newTotalFee));

}



很抱歉,如果这很多,我们将不胜感激。



我尝试了什么:



尝试打印出数组元素,而不是打印出索引但却陷入困境用户输入并与数组索引匹配


Sorry if this is a lot, any help would be appreciated.

What I have tried:

tried printing out array elements, instead printed out indexes but got stuck on taking the users input and matching it with the array index

推荐答案

我会这样说(但我打赌你的导师实际上已经指定了提示文本,所以我是不确定你需要什么样的帮助):



从上面显示的数组中选择两个元素,并将它们组合起来。
I would word it like this (but I bet your instructor has actually specified the prompt text, so I'm not sure what kind of help you need):

"Select two elements from the array shown above, and combine them."


这篇关于如何提示用户从数组中选择2个元素并将它们组合起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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