d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Whos Good With C++ > And Wants To Make Some Monies Each Week
Add Reply New Topic New Poll
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Oct 11 2012 09:29am
Need help with my weekly lab, due tonight
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Oct 11 2012 10:41am
Pm me for more info
Member
Posts: 827
Joined: Jan 16 2012
Gold: 0.00
Warn: 10%
Oct 11 2012 10:44am
post here.
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Oct 11 2012 11:11am
Code

// Lab 4-1
// Programer: Colin White
// Description: Program allowing us to calculate the

#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
//Variable Declarations

char card1;
char card2;
char card3;
char K;
char A;
char Q;
char J;
char T;

T = 10;
J = 10;
Q = 10;
K = 10;

//Description of the the program to the user instructing them how to enter the cards
cout << "This program calculates the value of 3 cards according to the blackjack rules."
  << "\nPlease enter T for Ten, J for Jack, Q for Queen, K for King, and A for Ace."
  << "\nPlease enter the number value of the card for the rest." << endl<<endl;

//The First card entry along with an If statement making sure they enter correct values
cout << "\tEnter the first card: ";
   cin  >> card1;

if (card1 < 2 > 9 || card1!=T || card1!=J || card1!=Q || card1!=K || card1!= A)
{
 cout << "Error: You have not entered a correct card number." <<endl<<endl;
 return 0;
}

cout << "\tEnter the second card: ";
cin  >> card2;
if (card2 < 2 > 9 || card1!=T || card1!=J || card1!=Q || card1!=K || card1!= A)
{
 cout << "Error: You have not entered a correct card number." <<endl<<endl;
 return 0;
}

cout << "\tEnter the third card: ";
cin  >> card3;

if (card3 < 2 > 9 || card1!=T || card1!=J || card1!=Q || card1!=K || card1!= A)
{
 cout << "Error: You have not entered a correct card number." <<endl<<endl;
 return 0;
}

T = 10;
J = 10;
Q = 10;
K = 10;

return 0;
}


Why is it not recognizing any of the letters? the if condition isn't working...
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 11 2012 11:20am
1) you need to type your letters
2) card3 < 2 > 9 --> only one boolean at a time
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Oct 11 2012 11:24am
What do you mean type my letters? lowercase?

Code
#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
//Variable Declarations

char card1;
char card2;
char card3;
char K;
char A;
char Q;
char J;
char T;

T = 10;
J = 10;
Q = 10;
K = 10;

//Description of the the program to the user instructing them how to enter the cards
cout << "This program calculates the value of 3 cards according to the blackjack rules."
  << "\nPlease enter T for Ten, J for Jack, Q for Queen, K for King, and A for Ace."
  << "\nPlease enter the number value of the card for the rest." << endl<<endl;

//The First card entry along with an If statement making sure they enter correct values
cout << "\tEnter the first card: ";
   cin  >> card1;

if ((card1 <= 1)||(card1 >= 10 )||(card1!=J)||(card1!=Q)||(card1!=K)||(card1!= A))
{
 cout << "\tError: You have not entered a correct card number." <<endl<<endl;
 return 0;
}

cout << "\tEnter the second card: ";
cin  >> card2;
if ((card2 <= 1)||(card2 >= 10 )||(card1!=T)||(card1!=J)||(card1!=Q)||(card1!=K)||(card1!= A))
{
 cout << "\tError: You have not entered a correct card number." <<endl<<endl;
 return 0;
}

cout << "\tEnter the third card: ";
cin  >> card3;

if ((card3 <= 1)||(card3 >= 10 )||(card1!=T)||(card1!=J)||(card1!=Q)||(card1!=K)||(card1!= A))
{
 cout << "\tError: You have not entered a correct card number." <<endl<<endl;
 return 0;
}

T = 10;
J = 10;
Q = 10;
K = 10;

return 0;
}

That is what i have so far...
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 11 2012 11:26am
Quote (Speed93 @ Oct 11 2012 01:24pm)
What do you mean type my letters? lowercase?


sorry, i missed it. you assigned them weird. J Q K and such are constants, so you should declare them as such and assign them when you declare them. you assigned them somewhere else and did it twice for unknown reasons

it looks like you're incorrectly using or. you should be using and. i dont really care to debug for you. so debug it or add logging statements if that doesnt fix your problem

This post was edited by carteblanche on Oct 11 2012 11:28am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll