heres a sample code i wrote:
#include<iostream>
using namespace std;
int main()
{
char A(0),B(0),total(0);
cout << "Please enter a value for A:";
cout << endl;
cin >> A;
cout << "Enter a value for B:";
cout << endl;
cin >> B;
cout << endl;
cout << endl;
total = A + B;
cout << "the total is: " << total;
cout << endl;
cout << "program end";
cout << endl<< endl << endl;
system ("pause");
return 0;
}
My assignment has a part in it that deals with entering values that are numbers and characters. should i post my assignment code or can you explain with my test code to how to take a number and convert it to type int.
My assignment is:
Write a program that scores a blackjack hand. In blackjack, a player receives from two to five cards. The cards 2 through 10 are scored as 2 through 10 points each. The face cards - jack, queen, and king are scored as 10 points. The goal is to come as close to a score of 21 as possible without going over 21. Hence, any score over 21 is called "busted". The ace can count as either 1 or 11, whichever is better for the user. For example, and ace and a 10 can be scored as either 11 or 21. Since 21 is a better score, this hand is scored as 21. An ace and two 8s can be scored as either 17 or 27. Since 27 is a "busted" score, this hand is scored as 17.
The user is asked how many cards she or he has, and the user responds with one of the integers 2,3,4, or 5. The user is then asked for the card values. Card values are 2 through 10, jack, queen, king, and ace. A good way to hande input is to use the type char so that the card input 2, for example, is read as the character '2', rather than as the number 2. Input the values 2 through 9 as the characters '2' through '9'. Input the values 10, jack, queen, king, and ace as the characters 't', 'j', 'q', 'k', and 'a'. (Of course, the user does not type in the single quotes.) Be sure to allow upper - as well as lowercase letters as input.
After reading in the values, the program should convert them from character values to numeric card scores, taking special care for aces. The output is either a number between 2 and 21 (inclusive) or the word Busted. Use fucntions, multiway branches, switch statements or nested if-else statements. Your program should include a loop that lets the user repeat the calculation until they are done doing so.
incase you are wondering me and USMarineMIke are not the same person. we are just in the same class with the same assignments!..
so heres my code so far but i just need to know the awnser to my question which is: is there a way to convert from char to int?
#include <iostream>
using namespace std;
class Blackjack
{
public:
void input();
void figureout();
void get_sum();
void output();
Blackjack(int cards);
Blackjack();
private:
int master_hand;
int raw_score;
int raw_score2;
int final sum;
char cards;
}
int main()
{
int input;
Blackjack input1;
do
{
input1= Blackjack(input);
input1.input();
input1.get_sum();
input1.figureout();
input1.output();
cout << endl;
cout << "Would you like to run the program again?(y or n)\n";
cin >> again;
cout << endl;
}while((again == 'y')||(again == 'Y'));
cout << endl << endl;
cout << "<program end>";
cout << endl << endl;
system("pause");
return 0;
}
void Blackjack::input()
{
cout << "Enter the values of your cards(how many ever cards you have in your hand):";
cout << endl;
while(cards == counter)
{
cin >> card;
}
im still working on it.. i know how to do most of it..except the question i asked.
Just wondering if the way is to use istream?.. or is there another way?

New Topic/Question
Reply




MultiQuote








|