NEED HELP WITH TWO BASIC PROGRAMS

Calculate AVERAGE/LETTER GRADE of student and a simple BLACKJACK game

Page 1 of 1

1 Replies - 601 Views - Last Post: 26 October 2009 - 11:53 PM Rate Topic: -----

#1 jimbrady176  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-October 09

NEED HELP WITH TWO BASIC PROGRAMS

Posted 26 October 2009 - 07:08 PM

Here is blackjack, far from done, don't even know where to start.

#include <iostream>
#include <ctime>


void deal(int& pc1_no, int& pc1_suit, int& pc2_no, int& pc2_suit, int& deal1_no, int& deal1_suit, int& deal2_no, int&deal2_suit);

void displayCard(int card_no, char pic);

int computeTotal(int card1_no,int card2_no);



int main()
{
	int pc1_no = 0;
	int pc1_suit = 0;
	int pc2_no = 0;
	int pc2_suit = 0;
	int deal1_no = 0;
	int deal1_suit = 0;
	int deal2_no = 0;
	int deal2_suit = 0;
	int card_no = 0;
	int card1_no = 0;
	int card2_no = 0;
	int bet = 0;
	char pic = ' ';
	char repeat = 'y';

do
{
	

	cout << "Please enter a bet (MINIMUM BET IS $5.  WHOLE AMOUNTS ONLY): ";
	cin  >> bet;


	cout << "Run program again (y/n): ";
	cin  >> repeat;
}while( (repeat == 'y') || (repeat == 'Y') );

return 0;

void displayCard(int card_no, char pic)
{
 
  int card_no = 0;
  char pic = ' ';

  switch (card_no)
  {
	case 1:
		cardAce(pic);
		break;

	case 2:
		cardTwo(pic);
		break;

	case 3:
		cardThree(pic);
		break;
	case 4:
		cardFour(pic);
		break;
	case 5:
		cardFive(pic);
		break;
	case 6:
		cardSix(pic);
		break;
	case 7:
		cardSeven(pic);
		break;
	case 8:
		cardEight(pic);
		break;
	case 9:
		cardNine(pic);
		break;
	case 10:
		cardTen(pic);
		break;
	case 11:
		cardJack(pic);
		break;
	case 12:
		cardQueen(pic);
		break;
	case 13:
		cardKing(pic)
		break;
  }
}

void cardTwo(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "2" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "2" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}

void cardThree(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "3" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "3" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardFour(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "4" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "4" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardFive(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "5" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "5" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardSix(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "6" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "6" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardSeven(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "7" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "7" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardEight(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "8" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "8" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardNine(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "9" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "9" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardTen(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "10" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "10" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardJack(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "J" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "J" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardQueen(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "Q" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "Q" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardKing(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "K" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "K" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}
void cardAce(char pic)
{
	  cout << "+-------+" <<endl;
	  cout <<"|" << "A" << setw(7) << "|" <<endl;				 //1
	  cout <<"|" << setw(8) << "|" <<endl;						//2
	  cout <<"|" << setw(3) << pic << setw(5) << "|" <<endl;	  //3
	  cout <<"|" << setw(8) << "|" <<endl;						//4
	  cout <<"|" << setw(8) << "|" <<endl;						//5
	  cout <<"|" << setw(8) << "|" <<endl;						//6
	  cout <<"|" << setw(5) << pic << setw(3) << "|" <<endl;	  //7
	  cout << "|" << setw(8) << "|" <<endl;					   //8
	  cout << "|" <<setw(7) << "A" << "|" <<endl;				 //9
	  cout << "+-------+" <<endl;
}




and here is what I have for the averaging a student's grade.

#include <iostream>
#include <iomanip>

using namespace std;

int getStudentID();
int getNumExams(int id);
double calculateTotal(double score, int j, int numExams);
double calculateAverage(double average, int j, double total);
char determineLetterGrade(double average, char letterGrade);
void displayAverageGrade(int id, double average, char letterGrade);



int main()
{
	int id = 0;
	int j = 0;
	int numExams = 0;
	double total = 0;
	double score = 0;
	double average = 0;
	char letterGrade = 'A';
	char repeat = 'y';

do
{
	id = getStudentID();
	numExams = getNumExams(id);
	total = calculateTotal(score, j, numExams);
	letterGrade = determineLetterGrade(average, letterGrade);
	displayAverageGrade(id, average, letterGrade);
	

	cout << "Run program again (y/n)?:  ";
	cin  >> repeat;

}while( (repeat == 'Y') || (repeat == 'y') );

return 0;
}

int getStudentID()
{
	int id = 0;
	cout << "Enter Student ID: ";
	cin  >> id;

	return(id);
}
int getNumExams()
{
	int numExams = 0;

	cout << "Please enter the number of exams: ";
	cin  >> numExams;

	if (numExams < 0)
	{
		cout << "ERROR - INVALID NUMBER OF EXAMS, MUST BE A NUMBER ABOVE ZERO: ";
		cin  >> numExams;
	}
	else
	{
	;
	}

	return(numExams);
}
double calculateTotal(double score, int numExams, int j, double total)
{
	


	for (j = 0; j < numExams; j++)
	{
		cout << "Exam" << (j + 1) << ": ";
		cin  >> score;

		total += score;

		return(total);
	}

	
}
double calculateAverage(double average, int numExams, double total)
{


	average = total/numExams;

	return(average);
}
double determineLetterGrade(char letterGrade, double average)
{


		if (average >= 90)
			{
			letterGrade = 'A';
			}
		else if ( (average >= 80) && (average <= 89) )
		{
			letterGrade = 'B';
		}
		else if ( (average >= 70) && (average <= 79) )
		{
			letterGrade = 'C';
		}

		else if ( (average >= 60) && (average <= 69) )
		{
			letterGrade = 'D';
		}
		else if (average <= 59)
		{
			letterGrade = 'F';
		}

	return(letterGrade);
}	
void displayAverageGrade(int id, double average, char letterGrade)
{
	cout << "Student ID: " << id << endl;
	cout << "Student Average: " << average << endl;
	cout << "Student Letter Grade: " << letterGrade << endl;
}



any help would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: NEED HELP WITH TWO BASIC PROGRAMS

#2 jwwicks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 162
  • Joined: 31-July 08

Re: NEED HELP WITH TWO BASIC PROGRAMS

Posted 26 October 2009 - 11:53 PM

Hello,

View Postjimbrady176, on 26 Oct, 2009 - 06:08 PM, said:

Here is blackjack, far from done, don't even know where to start.


First blackjack

Delete these lines from displayCard
  int card_no = 0;
  char pic = ' ';



Creat some data structure to track all 52 Cards
say a 4x14 char array
0 1 2 ...13
[A][2][3]...[K]
cardArray[0] = Spades
cardArray[1] = Diamonds
...
So cardArray[0][0] = Ace of Spades

or you could come up with a structure that holds both, the value and the suit.

struct cardType{
 int val;
 short suit; 
}Card;



I like the structure setup but might be a little beyond the class you're in.

Now write the deal function to use random to generate a number between 0-14 gives you the card
and also a random number between 0-5 gives you the suit. Each time you deal a card place a value in the array to show it's been dealt.

When you get that far post again. Make sure you can print out all 52 cards in the deck from the array...

Jw
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1