0

Ok, I am tryin to use the proper coded way that a few of you have asked, so don't yell if I screw up the first time, please. I was able to debug and run, but had many errors, I have fixed several already, biggest problems are that if I type outside parameters like 12 for 12 spots, I get outside access memory. Here's the assignment, and its already late:
We must make a C++ code for a Keno game, which takes a Keno Playslip, and you can play a number of spots 1-10, also you can pick your own numbers between 1-80, or choose for a quik pik, of 1-80 picks. Also, you have to choose if your playing $1, $2, or $3 per draw. Next, you have to display a Keno monitor that will display the winning numbers.

class KenoPlaySlip
{
private:
	int spots;
	int dollarAmount;
	int numberOfDraws;
	int *numbers;
	int newnumbers;
public:
	KenoPlaySlip();
	int *getNumbers();
	void setNumbers(int *newNumbers);
	void displayKenoPlaySlip();
	void prepareKenoPlaySlip();
};
#include <cstdlib>
#include <ctime> 
#include <iostream>
#include "KenoPlaySlip.h"
using namespace std;

KenoPlaySlip::KenoPlaySlip()
	{
	spots = 0;  
	dollarAmount = 0;
	numberOfDraws = 0;
	numbers = new int[spots];
}

int* KenoPlaySlip::getNumbers()
{
	return numbers;
}

void KenoPlaySlip::setNumbers(int *newNumbers)
{	
	numbers = newNumbers;
}

void KenoPlaySlip::displayKenoPlaySlip()
{
		cout << "Enter number of spots you want from 1-10: "<< endl;
		cin >> spots;

		numbers[spots];

	for(int i=1; i < spots; i++)
	{
			cout << numbers[i] << ", ";
	}
	if(spots >0 && spots < 10)
	{
		cout << "You can only enter 1-10 spots" << endl;
	}
	{
		cout << "Enter the newnumbers you want from 1-80 or enter QP for quik pik: "<< endl;
		cin >> newnumbers;

	for(int j=0; j < newnumbers; j++)
	{
		cout << newnumbers << " , ";	
	}
	if(newnumbers > 0 && newnumbers < 81)
	{
		cout << "You can only enter 1-80 newnumbers: " << newnumbers << endl;
	}
	{
	srand((unsigned)time(NULL)); 
    int random_integer; 
    for(int index=0; index<80; index++){ 
        random_integer = (rand()%10)+1; 
        cout << random_integer << endl;
	}
	{
	cout <<"Enter a dollar amount that you want per draw, $1, $2, or $3: "<< endl;
	cin>> dollarAmount;
	
	for(int k=1; k < dollarAmount; k++)
	{
		cout << dollarAmount << " ";	
	}
	if(dollarAmount == 1 ||dollarAmount == 2 || dollarAmount == 3)
	{
		cout << "You can only enter $1, $2, or $3: " << endl;
	}
	{
	cout<<"Enter how many consecutive draws you want to play, 1-5, 10, or 20: "<< endl;
	cin >> numberOfDraws;
	
	for(int l=1; l <= numberOfDraws; l++)
	{
		cout << numberOfDraws << " " << endl;
	}
	{
	if(numberOfDraws < 1 || numberOfDraws > 5) && (numberOfDraws != 10) && (numberOfDraws != 21)
	{
		cout << "You can only enter number of Draws 1-5, 10, or 20: " << endl;
	}
	cout << numberOfDraws ;
	}
	}
}
	}
	}
}
#include <iostream>
#include "KenoPlaySlip.h"
using namespace std;

int main()
{
	KenoPlaySlip slip;
	slip.getNumbers();
	slip.displayKenoPlaySlip();
	return 0;
}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

line 12 of the class constructor: you might as well just set numbers = 0 because new does nothing when called with a value of 0.

line 22: setNumbers(). What happens when numbers already has a value? Answer: huge memory leek!

line 30: what is that supposed to do? Its a do-nothing line (except access the array out-of-bounds)


line 36: That if condition is backwards. you want if( spots < 1 || spots > 10) line 42: ok, where did you declare newnumbers ?

There are probably other errors but thats enough for now from me.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.