I'm trying to make the code in a way so that the output "its a Yes or no question" will come out like 3 times before having a different output saying something else then resetting. I was thinking of using for(int i =0; i< 3; i++) but i don't know how or where i would enter it. I would appreciated if someone can help me out with this simple thing.
int main()
{
string moving = "yes";
string no = "no";
string input;
do {
cout << "Are you winning kreznik? " << endl;
cin >> input;
if (input == no) {
cout << "Then it should be a yes if you want to win. you will win for sure if you at least have that mustard seed of a yes! " << endl;
}
else{
cout << "Its a yes or no question kreznik... -_- " << endl;
}
} while (input != moving);
cout << "Good Job kreznik. Keep going. you will win for sure!!! " << endl;
return 0;
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string moving = "yes";
string no = "no";
string input;
int variable = 0;
do {
cout << "Are you winning kreznik? " << endl;
cin >> input;
for( int i =0; i < variable; i++){
if(i < variable){
if (input == no) {
cout << "Then it should be a yes if you want to win. you will win for sure if you at least have that mustard seed of a yes! " << endl;
}
else{
cout << "Its a yes or no question kreznik... -_- " << endl;
}
}
}
} while (input != moving);
cout << "Good Job kreznik. Keep going. you will win for sure!!! " << endl;
return 0;
}
that is my guess it may be something simpiler then that, i havent tested it yet but you get the idea
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string moving = "yes";
string no = "no";
string input;
constexprint NUM_OF_REPA{ 3 }; // <--- Added.
do
{
cout << "\nAre you winning kreznik? ";
cin >> input;
std::cout<<'\n';
for (int lc = 0; lc < NUM_OF_REPA; lc++)
{
if (input == no)
{
cout << "Then it should be a yes if you want to win. you will win for sure if you at least have that mustard seed of a yes!\n";
}
else
{
cout << "Its a yes or no question kreznik... -_- \n";
}
}
} while (input != moving);
cout << "\nGood Job kreznik. Keep going. you will win for sure!!! \n";
return 0;
}
Not sure about the if/else in the for loop, but it does produce this output:
Are you winning kreznik? no
Then it should be a yes if you want to win. you will win for sure if you at least have that mustard seed of a yes!
Then it should be a yes if you want to win. you will win for sure if you at least have that mustard seed of a yes!
Then it should be a yes if you want to win. you will win for sure if you at least have that mustard seed of a yes!
Are you winning kreznik? yes
Its a yes or no question kreznik... -_-
Its a yes or no question kreznik... -_-
Its a yes or no question kreznik... -_-
Good Job kreznik. Keep going. you will win for sure!!!
Yeah my goal is to make it to where it would output 1 at a time with each input that isn't a yes or no response then after that set amount of times I would want it to output a different message like "Stop Doubting. YES or NO?!!"
example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Are you winning kreznik? idk
Its a yes or no question kreznik... -_-
Are you winning kreznik? maybe
Its a yes or no question kreznik... -_-
Are you winning kreznik? i think
Stop Doubting. YES or NO.
Are you winning kreznik? yes
Good Job kreznik. Keep going. you will win for sure!!!
I managed to figure it out. what do you guys think? I would also would like to know if theres anything in it that can be better and more organized in this code if you guys are willing to share some suggestions.
int main()
{
string yes = "yes";
string no = "no";
string input;
int repeat = 0;
do {
cout << "Are you moving your life britt? " << flush;
cin >> input;
if (input == no) {
cout << "Then it should be a yes if you want to move your life. you will win for sure if you at least have that mustard seed of a yes! " << endl;
}
elseif (repeat <= 3) {
cout << "Its a yes or no question britt... -_- " << endl;
repeat++;
}
else {
cout << "Are you doubting yourself? its a simple yes or no..." << endl;
repeat = 0;
}
} while (input != yes);
cout << "Good Job britt. Keep going. you will win for sure!!! " << endl;
return 0;
}
int main()
{
string yes{ "yes" };
string no{ "no" };
string input;
int repeat{};
do
{
cout << "Are you moving your life britt? "; // <--- The following "cin" will "flush" the output buffer before any input is taken.
cin >> input;
if (input == no)
{
cout << "Then it should be a yes if you want to move your life. you will win for sure if you at least have that mustard seed of a yes!\n"; // <--- The extra space at the end has no use.
}
elseif (repeat <= 3)
{
cout << "Its a yes or no question britt... -_-\n";
repeat++;
}
else
{
cout << "Are you doubting yourself? its a simple yes or no...\n";
repeat = 0;
}
} while (input != yes);
cout << "Good Job britt. Keep going. you will win for sure!!!\n"; // <--- If this becomes a problem put the "endl" back.
return 0;
}
With the newer standards and the upgrades the use of "endl" is no longer as necessary. the new line, (\n), should be enough and as the comment noted a "cout" statement followed by a "cin" will flush the output buffer before any input is taken. You can use this to your advantage.
If repeat is is initialized to (0)zero then this: elseif (repeat <= 3) would be true 4 times. Not the 3 that you want. You may want to remove the (=).
do
{
std::cout << "\nAre you moving your life britt? "; // <--- The following "cin" will "flush" the bubber before any input is taken.
std::cin >> input;
if (input == no)
{
// <--- Changed. Added a "\n" so that the type does not reach the right side of the screen and wrap funny.
std::cout <<
"\nThen it should be a yes if you want to move your life. you will win for sure if you at\n""least have that mustard seed of a yes!\n"; // <--- The extra space at the end has no use.
}
elseif (repeat < 3 && input != yes)
{
std::cout << "\n Its a yes or no question britt... -_-\n";
repeat++;
}
elseif (repeat < 3 && input != yes)
{
std::cout << "\nAre you doubting yourself? its a simple yes or no...\n";
repeat = 0;
}
} while (input != yes);