c - 代码不起作用,并且没有执行定向任务
问题描述
该代码是不言自明的,但我需要帮助,因为当我使用它时,它会跳过所有“If”情况并直接跳转到下一个循环。“scanf”工作正常;变量“order”也正确接收输入。如果您知道如何解决它,请告诉我!祝你有美好的一天!
#include <stdio.h>
#include <string.h>
int main(){
int side [3]; // Fries(0), Fried Squid(1), Cheese Fries(2)
int combo [3]; // Spicy Chicken(0), Whopper(1), Double Whopper(2)
int drinks[3]; // Cola(0), Vanilla Shake(1), Lemonade(2)
int amount;
char order [20];
int total = 0;
for(int i = 0; i < 3; ++i){
combo[i] = 20;
total = total + 20;
}
for(int i = 0; i < 3; ++i){
side[i] = 20;
total = total + 20;
}
for(int i = 0; i < 3; ++i){
drinks[i] = 20;
total = total + 20;
}
while (total > 0){
printf("Make your order here: \n");
scanf("%s %d", order, &amount);
printf("%s\n", order);
if(order == "Fries"){
printf("A\n");A
if(side[0] < amount){
printf("Your order is invalid, and you are stinky.\n");
}
else{
printf("B\n");
printf("your order is here: %s x %d", order, amount);
total = total - amount;
}
printf("C\n");
}
printf("D\n");
}
return 0;
}
解决方案
我现在无法测试,但我认为您应该使用strcmp
或strncmp
比较字符串;运算符==
将只比较指针。
推荐阅读
- javascript - 我可以从相对路径提供 create-react-app 资产吗
- c# - C# 多维数组
- android - Android:以编程方式从剪贴板中删除单个项目
- python - 使用 Python 通过 Telnet 发送数据
- bluetooth - 是否有任何支持 MacOS/Linux/Unix 的蓝牙 4.0(支持 LE)USB 适配器?
- linq - GroupBy OrderBy Linq - 无效列
- wordpress - 如何在本机反应中为来自 WordPress API 的动态块添加轮播?
- haskell - 在 Haskell (GHCI) 中声明函数类型?
- azure-cosmosdb - Microsoft.Azure.Documents.Spatial.Point 的 JSON 序列化的 Asp.net 核心问题
- css - React Native,(使用响应式网格)组件太大的问题