Originally Posted by
WHOLEGRAIN
Code:
#include <iostream>
using namespace std;
int main()
{
cout<<"I just deleted some important files. Now, you will do as I say.\n";
int decision;
int x;
cout<<"Now, do as I say or those files will be forever lost. Press 1 for yes and 0 for no.\n";
for (x=1 ;x == 1; x++ ) {
int a;
cin>>decision;
if (decision == 1) {
cout<<"You have taken the right decision, my friend.\n";
a = 2;}
else if (decision > 1) {
cout<<"Are you a dumbass?\n";
a = 1;}
else if (decision == 0) {
cout<<"You will regret this!\n";
a = 1;}
if (a == 1) {
cout<<"You have been given another chance.\n";
x = x - 1;
cin.get();}
}
}
====
I'd like to count how many times the user has been given a second chance, how do I do this without rewriting everything?
How about this:
Code:
#include <iostream>
using namespace std;
int main()
{
cout<<"I just deleted some important files. Now, you will do as I say.\n";
int decision;
int count = 0;
cout<<"Now, do as I say or those files will be forever lost. Press 1 for yes and 0 for no.\n";
cin>>decision;
if (decision == 1) {
cout<<"You have taken the right decision, my friend.\n"
"Your files have been spared.\n\n";
cout<< "Welcome to the world of programming.\n"
"Now go learn C++ to write a better program than this.\n";
return 0;
}
else if (decision > 1) {
cout<<"Are you a dumbass?\n";
cout<< "You have failed the test...\n"
"You have been doomed to suffer deletion of all files on your computer.\n"
"Now PREPARE to SUFFER!!!" <<endl;
return 1;
}
else if (decision == 0) {
cout<<"You will regret this!\n";
while (decision == 0) {
if (count == 10) {
cout<< "Your chances have run out....\n"
"Prepare to suffer the consequences." <<endl;
return 1;
}
else if (count > 0 && count < 10){
cout<< "Warning! You are running out of chances.\n"
"Don't make me change my mind." <<endl;
}
cout<< "You have been given another chance.\n"
"Press 1 for yes, and 0 for no." <<endl;
cin>>decision;
count++;
}
cout<< "Your files have been restored.\n"
"Congratulations on coming to your senses." <<endl;
}
return 0;
}