我有一个脚本c ++
但是我运行这个脚本
当我写代码衬衫“ GC”或“ PR”时,此脚本错误
但我写的代码“ A”这个脚本工作
为什么呢?
是否如果条件为仅1个字符?
这是我的剧本,帮帮我。谢谢
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
char code,size,merk[15];
long price=0;
clrscr();
cout <<"\n \t GUCCI : GC";
cout <<"\n \t PRADA : PR \n";
cout <<"\n \t Armani : A";
cout <<"\n";
cout<<"Choose Your Shirt : ";cin>>code;
cout<<"Size : ";cin>>size;
if (code=='GC' || code=='gc')
{
strcpy(merk,"Gucci");
if (size=='S' || size =='s')
price=45000;
else if (size=='L' || size =='l')
price=35000;
else if (size=='M' || size =='m')
price=45000;
else
price=60000;
}
else if (code=='PR' || code=='pr')
{
strcpy(merk,"PRADA");
if (size=='S' || size == 's')
price=65000;
else if (size=='L' || size =='l')
price=75000;
else if (size=='M' || size =='m')
price=85000;
else
price=75000;
}
else if (code=='A' || code=='a')
{
strcpy(merk,"ARMANI");
if (size=='S' || size == 's')
price=75000;
else if (size=='L' || size =='l')
price=95000;
else if (size=='M' || size =='m')
price=45000;
else
price=35000;
}
else
{
cout<<"Wrong Code"<<endl;
}
cout<<"------------------------"<<endl;
cout<<"Merk : "<<merk<<endl;
cout<<"Price : "<<price<<endl;
getch();
}
最佳答案
code=='GC'
单引号用于单字符(“ GC”不是)。对字符串使用双引号(但是请记住,您不能将字符串与==
进行比较)...
由于您一次只能读取一个字符,因此您期望如何输入“ GC”?
关于c++ - 在C++中出现错误情况,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26290225/