接受大写或小写Y / n [英] accept upper or lower case Y/n

查看:94
本文介绍了接受大写或小写Y / n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以做什么来接受大写或小写 y或n在下面的

计划中。?

任何帮助将不胜感激


#include< iostream>

使用命名空间std;


//课程定义

class披萨

{

public:

Pizza(const char top [] =" cheese",const int size = 12,const double

Price = 8.99);

void setValue();

void displayValues();


private:

char topping [20];

int diameter;

双倍价格;

};


//构造函数

Pizza :: Pizza(const char top [],const int size,const double Price)

{

strcpy(顶部,顶部);

直径=尺寸;

价格=价格;

}

//设置披萨功能

void Pizza :: setValue()

{

cout<< 请输入您选择的顶部:"<<''\ n'';

cout<<''\ n'';

cin>>打顶;

cout<< ''\ n'';

cout<< 请输入您选择的尺寸:"<<''\ n'';

cout<< ''\ n'';

cin>>直径;

cout<<''\ n'';


if(topping!=" cheese")

price = 9.99;


if(diameter> 12)

价格=价格+ 1.5;

}

//调用披萨功能

void Pizza :: displayValues()

{

cout<<"你选择的比萨饼是 <<摘心<< " " <<直径LT;< "英寸披萨

for " $" <<<<<''\ n'';

}

//启动主引擎

void main( )

{

char选项[2];


披萨p;

cout<< ; ''\ n'';

cout<< ''\ n'';

cout<< " MAHARAJA''PIZZA" <<''\ n \ n';;

cout<< 你想要一个12英寸的奶酪吗?披萨? y / n:" ;;

cin>>选项;


if(选项[0] ==''n'')

p.setValue();

p.displayValues();


}

What can I do to accept either uppercase or lower case " y or n" in the
program below.?
any help will be appreciated

#include <iostream>
using namespace std;

//class definigtion
class Pizza
{
public:
Pizza (const char top [] = "cheese", const int size = 12, const double
Price = 8.99);
void setValue();
void displayValues();

private:
char topping [20];
int diameter;
double price;
};

//constructor
Pizza::Pizza (const char top[], const int size, const double Price)
{
strcpy (topping, top);
diameter = size;
price = Price;
}
//set pizza function
void Pizza::setValue()
{
cout << "Please enter your choice of topping: "<<''\n'';
cout<<''\n'';
cin>>topping;
cout<< ''\n'';
cout<< "Please enter your choice of size: "<<''\n'';
cout<< ''\n'';
cin>>diameter;
cout<<''\n'';

if (topping != "cheese")
price = 9.99;

if (diameter > 12)
price = price + 1.5;
}
//call pizza function
void Pizza::displayValues ()
{
cout<<"Your choice of pizza is a " <<topping<< " " <<diameter<< "in. pizza
for " "$" <<price<<''\n'';
}
//start the main engine
void main()
{
char option[2];

Pizza p;
cout<< ''\n'';
cout<< ''\n'';
cout<< " MAHARAJA''S PIZZA" <<''\n\n'';
cout<< "Do you want a cheese 12 in. pizza? y/n: ";
cin>> option;

if (option[0] == ''n'')
p.setValue();
p.displayValues();

}

推荐答案

" <<<<<''\ n'';

}

//启动主引擎

void main( )

{

char选项[2];


披萨p;

cout<< ; ''\ n'';

cout<< ''\ n'';

cout<< " MAHARAJA''PIZZA" <<''\ n \ n';;

cout<< 你想要一个12英寸的奶酪吗?披萨? y / n:" ;;

cin>>选项;


if(选项[0] ==''n'')

p.setValue();

p.displayValues();


}

" <<price<<''\n'';
}
//start the main engine
void main()
{
char option[2];

Pizza p;
cout<< ''\n'';
cout<< ''\n'';
cout<< " MAHARAJA''S PIZZA" <<''\n\n'';
cout<< "Do you want a cheese 12 in. pizza? y/n: ";
cin>> option;

if (option[0] == ''n'')
p.setValue();
p.displayValues();

}




" David" < d _ *** @ shaw.ca>在消息新闻中写道:uJFlc.362252

"David" <d_***@shaw.ca> wrote in message news:uJFlc.362252


Ig.133228@pd7tw2no ...
Ig.133228@pd7tw2no...
我可以做什么来接受大写或小写 y或n在下面的
程序中。?


{snip] //启动主引擎
void main()


返回main类型为int。如果你把它改成任何东西都是未定义的行为

else。

{
char option [2];

披萨p;
cout<< ''\ n'';
cout<< ''\ n'';
cout<< " MAHARAJA''PIZZA" <<''\ n\ n'';
cout<< 你想要一个12英寸的奶酪吗?披萨? y / n:" ;;
cin>>选项;
为什么你需要一个char数组作为选项?

if(option [0] ==''n'')
What can I do to accept either uppercase or lower case " y or n" in the
program below.?
{snip] //start the main engine
void main()
Return type of main is int. It''s undefined behavior if you change it to anything
else.
{
char option[2];

Pizza p;
cout<< ''\n'';
cout<< ''\n'';
cout<< " MAHARAJA''S PIZZA" <<''\n\n'';
cout<< "Do you want a cheese 12 in. pizza? y/n: ";
cin>> option; Why do you need a char array for option?
if (option[0] == ''n'')



简单,检查''n''或''N''即if(选项==''n''||选项==''N'')


-Sharad


Simple, check for both ''n'' or ''N'' i.e. if(option==''n'' || option == ''N'')

-Sharad


这篇关于接受大写或小写Y / n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆