VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 573|回复: 3

If Else if 语句

[复制链接]
57_avatar_middle
最佳答案
0 
在线会员 发表于 2020-5-9 08:26:43 | 显示全部楼层 |阅读模式
哪个大神帮我看看为什么我运行不了这段代码(初学者)If Else if 语句

#include <iostream>
using namespace std;

int main()
{
string outside();
cout<<"do you like going outside? "<<endl;
getline(cin, outside);
string food();
cout<<"do you like fish or pork? "<<endl;
getline(cin,food);
string weather();
cout<<"Do you like sun or rain? "<<endl;
getline(cin,weather);

if (outside="yes"&&food="pork"&&weather="sun")
{
  cout<<"you are a lot like a dog"<<endl;
}
else if(outside="yes"&&food="pork"&&weather="rain")
{
  cout<<"you are more like a dog"<<endl;
}
else if(outside="yes"&&food="fish"&&weather="rain")
{
  cout<<"you are more like a cat"<<endl;
}
else if(outside="no"&&food="fish"&&weather="rain")
{
  cout<<"you are alot like a cat"<<endl;
}
else if(outside="no"&&food="fish"&&weather="sun")
{
  cout<<"you are more like a cat"<<endl;
}
else if(outside="no"&&food="pork"&&weather="sun")
{
  cout<<"you are more like a dog"<<endl;
}
else{
  cout<<"you are a human"<<endl;
}
}





上一篇:C++游戏开发方向
下一篇:学习顺序到底怎么来的啊?
57_avatar_middle
最佳答案
25 
在线会员 发表于 2020-5-9 09:22:58 | 显示全部楼层
1.了解一下如何定义std::string变量
2.if语句中判断条件的 “=”和“==”是不同的
3.main函数的返回值
57_avatar_middle
最佳答案
0 
ico_lz  楼主| 发表于 2020-5-9 09:24:02 | 显示全部楼层
JLDawson 发表于 2020-5-9 09:22
1.了解一下如何定义std::string变量
2.if语句中判断条件的 “=”和“==”是不同的
3.main函数的返回值

谢谢大神很有帮助
51_avatar_middle
最佳答案
90 
online_admins 发表于 2020-5-9 09:25:41 | 显示全部楼层
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;

  5. int main(int argc, _TCHAR* argv[])
  6. {
  7.         string outside;
  8.         cout << "do you like going outside? " << endl;
  9.         getline(cin, outside);
  10.         string food;
  11.         cout << "do you like fish or pork? " << endl;
  12.         getline(cin, food);
  13.         string weather;
  14.         cout << "Do you like sun or rain? " << endl;
  15.         getline(cin, weather);

  16.         if (outside == "yes"&&food == "pork"&&weather == "sun")
  17.         {
  18.                 cout << "you are a lot like a dog" << endl;
  19.         }
  20.         else if (outside == "yes"&&food == "pork"&&weather == "rain")
  21.         {
  22.                 cout << "you are more like a dog" << endl;
  23.         }
  24.         else if (outside == "yes"&&food == "fish"&&weather == "rain")
  25.         {
  26.                 cout << "you are more like a cat" << endl;
  27.         }
  28.         else if (outside == "no"&&food == "fish"&&weather == "rain")
  29.         {
  30.                 cout << "you are alot like a cat" << endl;
  31.         }
  32.         else if (outside == "no"&&food == "fish"&&weather == "sun")
  33.         {
  34.                 cout << "you are more like a cat" << endl;
  35.         }
  36.         else if (outside == "no"&&food == "pork"&&weather == "sun")
  37.         {
  38.                 cout << "you are more like a dog" << endl;
  39.         }
  40.         else{
  41.                 cout << "you are a human" << endl;
  42.         }

  43.         return 0;
  44. }
复制代码
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

×【发帖 友情提示】
1、请回复有意义的内容,请勿恶意灌水;
2、纯数字、字母、表情等无意义的内容系统将自动删除;
3、若正常回复后帖子被自动删除,为系统误删的情况,请重新回复其他正常内容或等待管理员审核通过后会自动发布;
4、感谢您对VC驿站一如既往的支持,谢谢合作!

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号-4 )|网站地图wx_jqr

GMT+8, 2023-3-21 00:25

Powered by CcTry.CoM

© 2009-2021 cctry.com

快速回复 返回顶部 返回列表