F
Freyr
For some reason, my program won't kill itself when Pull == 'n' or the
counter is equal to zero.
I tried two different ways:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int Tokens=5;
char Pull;
cout << "You have " << Tokens << " tokens. Pull? ";
cin >> Pull;
if(Pull == 'Y' || 'y' && Tokens != 0) {
Tokens--;
srand( (unsigned)time( NULL ) );
int A, B, C, N=3; //Three wheels on spinner
A = rand()%N + 1;
B = rand()%N + 1;
C = rand()%N + 1;
cout << "[" << A << "] [" << B << "] [" << C << "]\n";
if(A==1 && B==1 && C==1) {
Tokens+=4;
cout << "You won 4 tokens!" << endl;
}
else if(A==2 && B==2 && C==2) {
Tokens+=8;
cout << "You won 8 tokens!" << endl;
}
else if(A==3 && B==3 && C==3) {
Tokens+=12;
cout << "You won 12 tokens!" << endl;
}
else {
cout << "You lost" << endl;
}
cout << "You have " << Tokens << " tokens. Pull? ";
cin >> Pull;
}
else {
cout << "Thanks for playing!" << endl;
}
return(0);
}
and
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int Tokens=100;
char Pull;
cout << "You have " << Tokens << " tokens. Pull? ";
cin >> Pull;
while(Pull == 'Y' || 'y') {
Tokens--; //Subtract one token for pull
srand( (unsigned)time( NULL ) );
int A, B, C, N=3; //Three wheels on spinner
A = rand()%N + 1;
B = rand()%N + 1;
C = rand()%N + 1;
cout << "[" << A << "] [" << B << "] [" << C << "]\n";
if(A==1 && B==1 && C==1) {
Tokens+=4;
cout << "You won 4 tokens!" << endl;
}
else if(A==2 && B==2 && C==2) {
Tokens+=8;
cout << "You won 8 tokens!" << endl;
}
else if(A==3 && B==3 && C==3) {
Tokens+=12;
cout << "You won 12 tokens!" << endl;
}
else {
cout << "You lost";
}
cout << "You have " << Tokens << " tokens. Pull? ";
cin >> Pull;
}
cout << "Thanks for playing!" << endl;
return(0);
}
I'm at a complete loss. Thanks for any help!
-Freyr
counter is equal to zero.
I tried two different ways:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int Tokens=5;
char Pull;
cout << "You have " << Tokens << " tokens. Pull? ";
cin >> Pull;
if(Pull == 'Y' || 'y' && Tokens != 0) {
Tokens--;
srand( (unsigned)time( NULL ) );
int A, B, C, N=3; //Three wheels on spinner
A = rand()%N + 1;
B = rand()%N + 1;
C = rand()%N + 1;
cout << "[" << A << "] [" << B << "] [" << C << "]\n";
if(A==1 && B==1 && C==1) {
Tokens+=4;
cout << "You won 4 tokens!" << endl;
}
else if(A==2 && B==2 && C==2) {
Tokens+=8;
cout << "You won 8 tokens!" << endl;
}
else if(A==3 && B==3 && C==3) {
Tokens+=12;
cout << "You won 12 tokens!" << endl;
}
else {
cout << "You lost" << endl;
}
cout << "You have " << Tokens << " tokens. Pull? ";
cin >> Pull;
}
else {
cout << "Thanks for playing!" << endl;
}
return(0);
}
and
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int Tokens=100;
char Pull;
cout << "You have " << Tokens << " tokens. Pull? ";
cin >> Pull;
while(Pull == 'Y' || 'y') {
Tokens--; //Subtract one token for pull
srand( (unsigned)time( NULL ) );
int A, B, C, N=3; //Three wheels on spinner
A = rand()%N + 1;
B = rand()%N + 1;
C = rand()%N + 1;
cout << "[" << A << "] [" << B << "] [" << C << "]\n";
if(A==1 && B==1 && C==1) {
Tokens+=4;
cout << "You won 4 tokens!" << endl;
}
else if(A==2 && B==2 && C==2) {
Tokens+=8;
cout << "You won 8 tokens!" << endl;
}
else if(A==3 && B==3 && C==3) {
Tokens+=12;
cout << "You won 12 tokens!" << endl;
}
else {
cout << "You lost";
}
cout << "You have " << Tokens << " tokens. Pull? ";
cin >> Pull;
}
cout << "Thanks for playing!" << endl;
return(0);
}
I'm at a complete loss. Thanks for any help!
-Freyr