gpt的回答
#include <stdio.h>
int main() {
int walletAmount = 0;
int choice, quantity;
int itemPrices[] = {10, 20, 30, 40}; // 商品价格数组,可以根据需要进行修改
printf("请输入您携带的金额数目:");
scanf("%d", &walletAmount);
printf("\n");
while (1) {
printf("请选择商品 (1-4),输入0结束购物:");
scanf("%d", &choice);
if (choice == 0) {
break;
} else if (choice < 1 || choice > 4) {
printf("无效的选项,请重新选择!\n\n");
continue;
}
printf("请输入购买数量:");
scanf("%d", &quantity);
if (quantity <= 0) {
printf("购买数量必须大于0,请重新选择!\n\n");
continue;
}
int totalPrice = itemPrices[choice - 1] * quantity;
if (totalPrice > walletAmount) {
printf("金额不足!购买失败。\n\n");
} else {
walletAmount -= totalPrice;
printf("购买成功!剩余金额:%d\n\n", walletAmount);
}
}
printf("感谢您的购物!祝您生活愉快!\n");
return 0;
}
#include <stdio.h>
int main()
{
int x,y,z;
for(x=0;x<=100;x++)
for(y=0;y<=100;y++)
{
z=100-x-y;
if(5*x+3*y+z*1/3.0==100)printf("x=%d,y=%d,z=%d\n",x,y,z);
}
return 0;
}