帮助!简单的for循环int值混淆 [英] HELP! Simple For Loop Int Value Confusion

查看:62
本文介绍了帮助!简单的for循环int值混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我真的需要帮助!!我正在上一门编程课,这项作业是在今晚进行的,从字面上看,这整个星期都在做...请看一下我的代码,让我知道我要去哪里了.当我设置"i"时,值设为0表示有效 当我将"i"设置为如果将value设置为1,则对于中等大小的尺寸来说是完美的选择;如果设置为2,则对于较大的尺寸来说是完美的选择;如果设置为3,则适合订​​购更大的尺寸.如何设置"i" 值,使其等于sizeArray中的所有选项,而不是只能将其设置为等于数组中的一个选项?我希望我有道理,我需要它阅读用户选择的比萨大小,然后将其与相应的价格相匹配.我是 确保这可能很简单.非常感谢!

Hi, I really need help guys!! I'm taking a programming class and this assignment is due tonight, literally been working on this all week now... Please look at my code and let me know where I'm going wrong. When I set the "i" value to 0 it works perfectly for ordering a size small pizza, when I set the "i" value to 1 it works perfectly for size medium, when set to 2, works perfectly for a large, and when set to 3, works perfect for ordering an extra large size. How can I set the "i" value so that it equals ALL the options in the sizeArray instead of only being able to just set it equal to one option in the array?! I hope I'm making sense, I need it to read what size pizza the user chooses then match it with the corresponding price. I'm sure it's probably something simple. THANK YOU SO MUCH!


            for (int i = 0; i <= sizeArray.Length; i++) ////The following code only runs CORRECTLY when the user chooses "s" since "i" is equal to 0. I need it to run correctly whether the user enters, s, m, l, or xl.

推荐答案

这些类型的操作通常是在开关盒的情况下完成的.或自定义类披萨",这样您就可以完成一个数组.通常,多个并列阵列会带来更多麻烦,而不值得.

These kinds of operations are normally done with a switch case. Or a custom class "pizza", so you got a single array to itterate over. Multiple paralell arrays are usually more trouble then worth.

我认为您想要与此类似的代码:

I think you want code similar to this:

for(int i = 0; i < sizeArray.lenght; i++){
  if(sizeArray[i] == pizzaSize){
    //use i for the other arrays
    double Price = priceArray[i];
    double extra = extraArray[i];
  }
}


这篇关于帮助!简单的for循环int值混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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