我正在尝试使用带有字符串的语句来使用我的代码 [英] I'm trying to get my code to use if statements with strings
本文介绍了我正在尝试使用带有字符串的语句来使用我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果这个人说不,如果他说是或者我会这样做,或者在某件事情上会有不同的反应,那我就试着去做。
< pre lang =c ++>
#include < iostream >
#include < string >
int main()
{
使用 namespace std;
cout<< 你叫什么儿子!?<< ENDL;
字符串名称;
cin>>名称;
cout<<名称<< ,嗯,奇怪的名字,别介意!<< ENDL;
cout<< 我有一个对你的追求,你有兴趣吗?
char 我会。
我将不。;
string我会。
string我将不。;
cin>>我会。;
cin>>我将不。
if (我将不。)cout<< 好的,那就死了!<< ENDL;
if (我会。)cout<< 我需要你从崛起的戈尔布林袭击中拯救村民,向东向我证明你是值得的。 << ENDL;
return 0 ;
}
我的尝试:
我试过这个约30分钟,我只是不知道该怎么办?
解决方案
你需要学习正确的语法C ++。你的代码不喜欢编译器。
代码提示:
char I_will; // 永远不会在vars中使用空间或点
字符串I_will = 我会。 // 声明字符串并填写;
if (compare(I_will, 我不会。)== 0 ) // compare(结果为0表示true)=>教程
上一些课程精细的字符串教程。
你需要认真学习C ++及其语法。
以下是语言作者对C和C ++参考书的链接。注意,C是C ++的祖先,所以知道C对C ++总是有用。
C编程语言 - 维基百科,免费的百科全书 [ ^ ]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2。 pdf [ ^ ]
http://www.ime.usp。 br / ~pf / Kernighan-Ritchie / C-Programming-Ebook.pdf [ ^ ]
C ++编程语言 [ ^ ]
I'm trying to get if the person says no it will do a repsonse if he says yes or I will do it, or something in that matter it will give a different response.
#include <iostream>
#include <string>
int main()
{
using namespace std;
cout << "What is your name son!?" << endl;
string name;
cin >> name;
cout << name << ", hmm, strange name, never mind that!" << endl;
cout << "I have a quest for you, are you interested?"
char I will.;
I will not.;
string I will.;
string I will not.;
cin >> I will.;
cin >> I will not.;
if (I will not.) cout << "Okay then, be gone mortal!" << endl;
if (I will.) cout << "I need you to save the villagers, in the east from a rising golblin attack to prove to me you are worthy." << endl;
return 0;
}
What I have tried:
I tried doing this for around 30 mins, I just don't know what to do?
解决方案
You need to learn the right syntax in C++. Your code doesnt like the compiler.
tips in code:
char I_will;//never ever use space in vars or point string I_will = "I will."//declare the string and fill it; if (compare( I_will, "I will not.") == 0 ) //compare ( result is 0 for true) => tutorial
Take some lessons at this fine string tutorial.
You need yo learn seriously C++ and its syntax.
Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]
C++ Programing Language[^]
这篇关于我正在尝试使用带有字符串的语句来使用我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文