所以我想创建一个加1的整数的函数每次有人回应是的,这是我的代码:C++:试图创建1添加到整数的函数,当有人在控制台说“是”
#include "yesToNumber.h"
#include <string>
using namespace std;
int yesToNumber(string yes, int numberOfYes)
{
if ("yes"=="yes")
{
numberOfYes++;
yes = "";
}
}
但我不知道在哪里把功能在我的主要代码:
#include <iostream>
#include <string>
#include "yesToNumber.h"
using namespace std;
int main()
{
string agree, dontAgree;
cout<<"The question is : Do you have a computer ? Please answer with yes or no."<<endl;
cout<<"You have a computer."<<endl;
cin>>agree;
cout<<"You don't have a computer."<<endl;
cin>>dontAgree;
cout<<"number of people who said yes : "<<agree<<"/number of people who said no"<<dontAgree<<endl;
return 0;
}
所以我寻求帮助,和一些小技巧!
'如果( “是” == “是”)'? – BlackDwarf
这个程序是一个典型的案例,你应该阅读它,并试图说服自己,为什么它会做你想做的事情(因为它看起来好像没有)。将其分解成小任务,可能是逐行。 – mah
只需更改为'if(yes ==“yes”)''。作为微不足道的问题结束投票。 –