萌新求助为什么这个主程序不能自动计算商品的总价格和重量,只能
c#吧
全部回复
仅看楼主
level 1
李容易◎ 楼主
萌新求助为什么这个主程序不能自动计算商品的总价格和重量,只能出现商品的名字,而且一旦输入到确定好的商品总数量就自动归零[泪]
2019年03月07日 15点03分 1
level 9
输出price下面加这两句
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
2019年03月08日 03点03分 3
谢大神[太开心]我试一下
2019年03月08日 03点03分
大神我放了所有的代码总价还是无法计算[小乖]
2019年03月08日 03点03分
level 1
李容易◎ 楼主
改了一下成这个样子了,不会自动返回但是无法计算总价和数量[小乖]
2019年03月08日 03点03分 4
level 1
李容易◎ 楼主
namespace ScanCode
{
class PriceCalculator
{
//扫码计价模块
public const float bread_price = 5.32F; //产品价格
public const float noodles_price = 1.26F;
public const float cola_price = 3.50F;
public const double bread_code = 9787302279174; //产品条形码
public const double noodles_code = 456;
public const double cola_code = 789;
public const int kind1 = 0;
public class Shopping
{
public string name { get; set; }//商品名称,即char name[50]
public float price { get; set; }//价格
public double code { get; set; }//记录商品条形码
public int kind { get; set; }//类
};
//定义shopping类的对象数组shop
public static Shopping bread = new Shopping { name = "bread", price = bread_price, code = bread_code, kind = kind1 };
public static Shopping noodles = new Shopping { name = "noodles", price = noodles_price, code = noodles_code, kind = kind1 };
public static Shopping cola = new Shopping { name = "cola", price = cola_price, code = cola_code, kind = kind1 };
public static Shopping[] shop = new Shopping[3] { bread, noodles, cola};
public static void Main(string[] args)
{
float price = 0;
int num;
double code;
bool judge = false;
Console.Write("Please press the toal number of goods: ");
num = int.Parse(Console.ReadLine());
Console.WriteLine("now please put things you have bought and if you don't want to continue add goods, press0");
while (num != 0)
{
code = Double.Parse(Console.ReadLine());
if (code == 0) break;
else
{
int i;
for (i = 0; i < 3; i++) //条形码
2019年03月08日 03点03分 5
level 1
李容易◎ 楼主
,商品归类
{
if (code == shop[i].code)
{
price += shop[i].price; //商品总价
Console.WriteLine(shop[i].name + " has been charged successfully!");
num = num - 1;
shop[i].kind = shop[i].kind + 1;
judge = true;
}
}
if (judge == false)
{
Console.WriteLine("This good has not been searched successfully!");
}
judge = false;
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
Console.WriteLine();
Console.WriteLine("****************************");
Console.WriteLine("list of goods you have bought: ");
for (int i = 0; i < 3; i++)
{
if (shop[i].kind != 0)
{
Console.WriteLine(shop[i].name + " " + "*" + shop[i].kind);
}
}
Console.WriteLine("***********************");
Console.Write("The total price is: ");
Console.Write(price);
}
}
}
}
2019年03月08日 03点03分 6
level 1
李容易◎ 楼主
求大神看看哪里还有遗漏[小乖]
2019年03月08日 03点03分 7
level 9
加在这个位置
2019年03月08日 04点03分 8
好的[太开心]我再试一下
2019年03月08日 04点03分
大佬[小乖]请问怎么把现实的文字换到下一行呀
2019年03月08日 08点03分
就是按任意键继续那一句
2019年03月08日 08点03分
@李容易◎ 按我截图的写就换到下一行了啊
2019年03月08日 08点03分
level 1
李容易◎ 楼主
终于成功了[太开心]请问大佬怎么把按任意键继续换到下一行呀
2019年03月08日 08点03分 9
1