我正在尝试做一个简单的do while循环,其中除'y'或'n'以外的任何字母都无效并且循环重复.有谁知道为什么这个循环总是评估为假?即使输入了有效字符?
char user_response[2];
do {
printf("\nDo you want to process another range (y or n): ");
scanf("%1s", user_response);
user_response[0] = tolower(user_response[0]);
}
while (user_response[0] != 'y' || user_response[0] != 'n');
return user_response[0];
Run Code Online (Sandbox Code Playgroud) 有没有办法摆脱3个警告:"从字符串文字转换为'char*'已被弃用"
这些是我的形状构造.它们是shapes基类的派生类.
我收到了这3行的警告.
right_triangle right_triangle("RIGHT-TRIANGLE-1", 5.99, 11.99);
square square ("SQUARE-1", 11.99);
rectangle rectangle ("RECTANGLE-1", 11.99, 5.99);
Run Code Online (Sandbox Code Playgroud)
由于所有3个类基本上都是相同的,我将使用right_triangle对象作为示例.在构造函数中,创建了有关形状的所有内容.
这是班级.
class right_triangle : public shapes
{
char *p_name;
float base,
height,
hypotenuse;
public:
void show_shape ();
right_triangle (char name[17], float base, float height);
~right_triangle() {}
};
Run Code Online (Sandbox Code Playgroud)
这是构造函数.
//**********************************************************************
//* Right triangle constructor *
//**********************************************************************
right_triangle::right_triangle(char name[17], float rt_base, float rt_height)
{
// Print constructor lines
cout << "\n\n\nCreating right triangle shape";
cout << "\n with base = " << rt_base …Run Code Online (Sandbox Code Playgroud)