带有多个字符的字符串 [英] string with mutiple characters

查看:78
本文介绍了带有多个字符的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是程序问题:


30天的月份有720小时,31天的月份有744小时。

2月,28天,有672个小时。通过询问用户月份(按名称)并验证

输入的小时数不超过最大值来增强下面

程序代码的输入验证

整月的数量。有一张桌子显示每个月的天数和

他们的小时数。我没必要输入它们。我刚接触C ++

而且我有问题分配字符串值与...或''符号。

请查看我几个月的变量声明并告诉我我做了什么

错了。加上我应该使用开关或者如果声明

批准为12个月。注意,我不能用数组函数来解决这个问题。这是代码。


#include< iostream>


#include< iomanip>


#include< string>


使用命名空间std;


int main()


{


int小时;


双倍收费;


char Choice,Month [40];


char 1月[40] =''1月';


//询问信息


cout<<"此程序计算

客户的每月互联网使用费。 "<<<< endl<< endl;


cout<<& :" ;;


cin>>选择;


while(!(选择==''A''||选择= ='''B''||选择==''C''))


{


cout<<"你必须输入包AB或C.请再试一次!"<< endl;


返回0;


}


cout<<"您需要在几个月内计算客户使用费? :" ;;


cin.getline(月,40);


cin.ignore();

cout<< endl<< endl;


if(strcmp(Month,January)== 0)


cout<<"字符串" ;;


/ *开关(月)


{


case" January":cout<<"输入<<<<<<<<"" !

:" ;;


while(小时> 744&小时< 0)

{


cout<<""<<<<<<<<<< endl;


cout<<"并且您输入的小时数不能小于0."<< endl;


cout<<"请输入正确的小时! :" ;;


cin>>小时;


cout<< endl<< endl;


}


}


* /


// cout< <"<<< Month"月份使用了多少小时? ? :" ;;


// cin>>小时;


// if(小时> 744 ||小时< 1 )


// cout<<"您的互联网访问时间不得超过744小时或小于

1小时。<< endl;

开关(选择)


{

case''A'':if(Hour< = 10)


{


费用= 9.95;


cout<<"你的在线时间是:<<<<<<<< endl;


cout<<"您的互联网费用是:"<<<<<< endl;


休息;


}


if(小时> 10)
< br $>
{


费用= 9.95 +((小时-10)* 2);


cout<< 您的在线时间是:<<< Hour<< endl;


cout<<"您的互联网费用是:"<<<<< < endl;


休息;


}

案例''B'':if(Hour< ; = 20)


{


费用= 14.95;


cout<<"您在线时间为:<<<<<< endl;


cout<<"您的互联网费用为:<<< Charge<<结束;


休息;


}


if(小时> = 20)


{


费用= 14.95 +((20小时)* 1);


cout<<"在线时间为:"<<<<<< endl;


cout<<"您的互联网费用为:"< <费用<< endl;


休息;


}

案例''C'':费用= 19.95;


cout<<"在线时间为:<<<<<< endl;


cout<<"你的网络费用是:<<<费用<< endl;


休息;



}


}

解决方案

Richard写道:< blockquote class =post_quotes> [blatantdo do do work请求编辑]




告诉你什么,理查德。给我你的导师电子邮件地址,并且

我会直接将答案发给他,为你省去麻烦。


char January [ 40] ='''1月';


将上面一行更改为:


char January [40] =" January" ;;


字符变量使用单引号,字符串使用双引号。


非常感谢。这就是我所需要的。


< An ********** @ gmail.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...

char January [40] =''January'';

将上面的行更改为:

char January [40] =" January";

字符变量使用单引号,字符串使用双引号。



Here is the program problem:

Month with 30 days have 720 hours, and month with 31 days have 744 hours.
February, with 28 days, has 672 hours. Enhance the input validation of the
program code below by asking user for the month (by name), and validating
that the number of hours entered is not more than the maximum number of the
entire month. There is a table that display how many days in each month and
their hours. It is unnecessary to for me to type them out. I new to C++
and I have problem assigning string value wheather with the " or '' symbol.
Please look at my variable declaration for the months and tell me what I did
wrong. Plus sugguest wheather i should use the switch or if statements
approve to 12 months. Note, I cannot use array function to solve this
problem. Here is the code.

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

int main()

{

int Hour;

double Charge;

char Choice ,Month[40];

char January[40]=''January'';

// ask for information

cout<<"This program calculate the monthly internet usage charge for a
customer. "<<endl<<endl;

cout<<"What Internet package have you purchased A,B or C? : ";

cin>>Choice;

while (!(Choice ==''A'' || Choice ==''B''|| Choice == ''C''))

{

cout<<"You must enter package A B or C. Please try again!"<<endl;

return 0;

}

cout<<"What month do you need to calculate customer usage charge? :";

cin.getline(Month,40);

cin.ignore();

cout<<endl<<endl;

if (strcmp(Month,January)==0)

cout<<"The string";

/*switch(Month)

{

case "January": cout<<"Enter the hours usage for the month of "<<Month<<" !
:";

while (Hour > 744 && Hour < 0 )

{

cout<<"There are only 744 hours in the month of "<<Month<<endl;

cout<<"and you cannot enter hour usage less than 0."<<endl;

cout<<"please enter the correct hour! : ";

cin>>Hour;

cout<<endl<<endl;

}

}

*/

//cout<<"How many hours were used for the month of "<<Month" ? : ";

//cin>>Hour;

//if (Hour > 744 || Hour < 1)

//cout<<"You cannot have internet access longer than 744 hours or less than
1 hour."<<endl;
switch (Choice)

{
case ''A'': if (Hour <=10)

{

Charge =9.95;

cout<<"Your hours online is: "<<Hour<<endl;

cout<<"Your internet charge is: "<<Charge<<endl;

break;

}

if (Hour > 10)

{

Charge = 9.95 +((Hour-10)*2);

cout<<"Your hours online is: "<<Hour<<endl;

cout<<"Your internet charge is: "<<Charge<<endl;

break;

}
case ''B'': if (Hour <=20)

{

Charge =14.95;

cout<<"Your hours online is: "<<Hour<<endl;

cout<<"Your internet charge is: "<<Charge<<endl;

break;

}

if (Hour >= 20)

{

Charge = 14.95 +((Hour-20)*1);

cout<<"Your hours online is: "<<Hour<<endl;

cout<<"Your internet charge is: "<<Charge<<endl;

break;

}
case ''C'': Charge = 19.95;

cout<<"Your hours online is: "<<Hour<<endl;

cout<<"Your internet charge is: "<<Charge<<endl;

break;


}

}

解决方案

Richard wrote:

[blatant "do my homework" request redacted]



Tell you what, Richard. Give me your instructors email address, and
I''ll send the answer directly to him, saving you the trouble.


char January[40]=''January'';

change the line above to:

char January[40]="January";

character variables use single quotes, strings use double quotes.


Thanks so much. That is all I need.

<An**********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

char January[40]=''January'';

change the line above to:

char January[40]="January";

character variables use single quotes, strings use double quotes.



这篇关于带有多个字符的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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