Я новичок в программировании на C ++ и ничего не делал за неделю, поэтому я возился с вещами, которые знаю до сих пор, чтобы посмотреть, придется ли мне снова что-то обсуждать.
Тем не менее, я столкнулся с проблемой с bools (до сих пор не использовал их).
Источник:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
signed long int x;
unsigned short int y = 12345;
bool POSX;
bool yes;
cin >> x;
if (x >= 0)
{
POSX = true;
}//end of if for bool
else
{
POSX = false;
}
cout << "This is the current value of X: " << x << endl;
if(x < y)
{
cout << "x is less than the integer y \n \n";
}//end of if
else
{
cout << "y is greater than the integer x \n \n";
}//end of else
cout << "The current value of Y is: " << y << endl << endl << endl;
cout << "Is X positive?: " << POSX << endl << endl;
cout << "How much more would X need to be to surpass y? The answer is: " << y - x << endl;
if(x > y)
{
cout << "well, actually, x is greater than y by: " << y - x << " so you would need to add that to get to the value of x" <<endl <<endl;
}//end of if
cout << "Do you like cookies? Enter below. . ." <<endl;
cin >> yes;
if(yes = "yes") // should this be if(yes = 1)?
{
cout << "I do too! But only when they are soft and gooey!";
} //end of if for bool yes
else
{
cout << "Well, join the dark side, and you may be persuaded by the power of cookies and the power of the dark forces!";
}//end of else for bool yes
char f;
cin >> f;
return 0;
} //end of main
Проблема, с которой я сталкиваюсь, заключается в том, что когда я пытаюсь скомпилировать, программа закрывается, прежде чем я вижу результат вопроса о cookie (поэтому мне нужно установить точку останова в компиляторе), и, во-вторых, смотрите ответ, он всегда приходит с ответом да, а не что-нибудь еще.
Таким образом, если я поставлю no в качестве входных данных, он все равно выведет if для bool yes, будучи истинным. Я не уверен, правильно ли я определяю условие if в последнем утверждении.
Может ли кто-нибудь помочь?