我一直试图运行以下代码。但是,我得到的唯一输出是"进程返回0(0x0)。我似乎无法理解代码的错误。我是编程新手。任何帮助表示赞赏。谢谢!
代码:
#include<stdio.h>
#include<stdlib.h>
int argentina(int units,int a_price,int *as);
int main()
{
int units,min_cost;
int a_price=50;
int a_stock=100;
int b_stock=100;
char country[10];
printf("Enter the name of the country");
gets(country);
printf("Enter the number of units");
scanf("%d",&units);
if(country=="argentina")
{
min_cost=argentina(units,a_price,&a_stock);
printf("%d : %d : %d",min_cost,b_stock,a_stock);
}
return 0;
}
int argentina(int units,int a_price, int *as)
{
int cost;
if(units >0 && units<=100)
{
cost=a_price * units;
*as=*as - units;
return cost;
}
}
答案 0 :(得分:0)
我会设置一个名为toCompare的char[]
(或类似的东西 - 你必须以这样的方式命名它以便将来理解它)并使用strcmp
来比较字符串。在这里阅读有关函数的内容:http://www.tutorialspoint.com/c_standard_library/c_function_strcmp.htm
char toCompare[15];
char country[15];
int ret;
strcpy(toCompare, "argentina");
gets(country);
ret = strcmp(toCompare, country);
if(ret == 0)
{
min_cost=argentina(units,a_price,&a_stock);
printf("%d : %d : %d",min_cost,b_stock,a_stock);
}