473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

does anybody some code for this

Have this much done but need help with this bit of code:

allow user to modify existing draw data. I think I need a counter to
give week numbers so the user can select a week number rather than a
date.

I need to view data for a selected week given the week number or date.

need some controls on not allowing the ball number to go >49 or <0 and
no duplicates.

the date needs some work on so the user can only enter numbers not
letters.

any help would be great.
/************************************************** ********************************************
*
* Carl's Assignment
*
*
*
* Here is a list of tasks to consider
* ___________________________________
*
* * Change the Display Routine to display the complete list of
* 52 Records simultaniously.
* You'll need to alter the count
*
* * Alter the Comments, and add extra ones
*
* * Write a Routine to edit an existing Record
*
* * Write a Routine that checks that the Ball Values entered are
within Range ( 1 - 49 )
*
* * Write a Routine that checks that no duplicate Ball Values are
entered
* (run this check after every entry)
*
* * THE BIG ONE - Write a Routine that checks the Date is valid
*
* * Think about what will happen when the Array is full & you put in
an additional Entry
*
*
************************************************** *********************************************/

#include <iostream.h>
#include <math.h>
#include <process.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>


// Function prototypes
void GetInput();
void DisplayValues();

void ChoiceDefault();
void AnyKey();

//Global variables (declared outside main() - so visable (i.e.
accessable) to whole program functions and all!
char datearray[53][10]; // 2-Dimensional array 52 rows, 9 columns.
int balls[53][36];

void main()
{

char date[10];
int choice=0, x=0, y=0;
int insertionPoint=0;


int i =0, j = 0, k = 0;
//initialise global 'datearray' as a string of asterixes and 'balls'
array with 0's
for(j=0; j<53; j++)
{
for(i=0; i<8; i++)
{
if (i == 8)
{
datearray[j][i] = '\0';//terminate string with null character
}
else
{
datearray[j][i] = '*';// initialise datarray with asterix
characters
}
for (int k=0;k<8;k++)
balls[i][k] = 0;

}
}
// open Date.txt file to get data from
ifstream inClientFile("Date.txt", ios::in); // open file for input
if(!inClientFile) // handle "could not open file" error
{
cerr << "File could not be opened" << endl;
exit(1);
}

// read data (date & two numbers) from Date.txt file
i=0; // must reset "i" to zero
while (inClientFile >> date)// read (next) "line" from file

{
for (k=0;k<7;k++)
inClientFile>>balls[i][k];
for(j=0; j<9; j++)
{
datearray[i][j] = date[j]; // copy date from 'date' tempory
variable into datearray
}

i++;
}
insertionPoint = i;//remember where to insert next new data
while (true)
{
// Clear screen
system("cls");

//Print Menu choices on screen
cout << "\n\n\t\tMENU:\n\n"<< "\t1 - Enter New Date\n"<< "\t2 - Print
out contents of global array on screen\n" << "\t999 - to exit";

//Get user's choice
cout << "\n\nEnter your choice : ";
cin >> choice;

//if 999 entered the jump out of while loop to finish
if (choice == 999) break;

//act on users menu choice
switch (choice)
{

case 1:
GetInput();
break;

case 2:
DisplayValues();
break;

default:
ChoiceDefault();
break;
}
}
system("cls");

/*
This section was of no use, as it was just repeating the display
before exiting the program
//Write contents of global array to screen
// output contents of date array to file
for(j=0; j<10; j++)
{
for(k=0; k<9; k++)
{
cout << datearray[j][k];
}
cout << "\t" << balls[j][0] << "\t" << balls[j][2];
cout << "\n";
}
*/

//Write data from arrays out to Lottery file
ofstream outClientFile("Date.txt", ios::out); // open file for output
if(!outClientFile) // handle error if file cannot be opened
{
cerr << "File could not be opened" << endl;
exit(1);
}

// exiting program, so output contents of datearray and balls to
Date.txt file
for(i=0; i<52; i++)
{
outClientFile << datearray[i];
for (j=0;j<7;j++)
outClientFile << " " << balls[i][j];
outClientFile << endl;
}
}
// Function Definitions
void GetInput()
{
int inspoint;
int ball1int = 0;
int ball2int = 0;
int ball3int = 0;
int ball4int = 0;
int ball5int = 0;
int ball6int = 0;
int ball7int = 0;
int j;
char date[10];

system("cls");
cout << "\nEnter new date (dd/mm/yy) :";
cin >> date;
cout << "\nEnter First Lottery Number :";
cin >> ball1int;
cout << "\nEnter Second Lottery Number :";
cin >> ball2int;
cout << "\nEnter Third Lottery Number :";
cin >> ball3int;
cout << "\nEnter Fouth Lottery Number :";
cin >> ball4int;
cout << "\nEnter Fifth Lottery Number :";
cin >> ball5int;
cout << "\nEnter Sixth Lottery Number :";
cin >> ball6int;
cout << "\nEnter Bouns Ball :";
cin >> ball7int;


// Find insertion point
for(j=0; j<10; j++)
{
if (datearray[j][0] == '*')
{
inspoint = j;
cout << "inspoint = " << inspoint << endl;
break;
}
}
//Insert new date into datearray and new numbers into balls, global
arrays.
for(j=0; j<10; j++)
{
datearray[inspoint][j] = date[j];
}
balls[inspoint][0] = ball1int;
balls[inspoint][1] = ball2int;
balls[inspoint][2] = ball3int;
balls[inspoint][3] = ball4int;
balls[inspoint][4] = ball5int;
balls[inspoint][5] = ball6int;
balls[inspoint][6] = ball7int;

}

void DisplayValues()
{
int j, k;
//Write contents of global arrays (datearray and balls) to screen
for(j=0; j<10; j++)
{
for(k=0; k<10; k++)
{
cout << datearray[j][k];
}
for(k=0; k<7; k++)
{
cout << "\t" << balls[j][k];
}
cout << "\n";
}
}
void ChoiceDefault()
{
system("cls");
cout <<"\n\n\n\n\tYou entered a number not on menu Menu ";
cout << "\n\n\n\nPress return for Main Menu" << endl;
getchar();
}
void AnyKey()
{
char ch;
cout << "\n\nPress any Key to Continue" << endl;
ch=getch();
cout << endl;
}
Jul 22 '05 #1
1 1898
carl bloc wrote:

Have this much done but need help with this bit of code:
Please be more specific. What help? What are your problems in specific?

allow user to modify existing draw data. I think I need a counter to
give week numbers so the user can select a week number rather than a
date.
Well. If you currently are unable to calculate the week number from a given
date then yes, storing a week number would solve your problem. But calculating
it from the date is more elegant. How to calculate it? Take paper, pencil
and try to figure out: Which week of the year holds the 25. Mai 2004.
If youcan answer that with only paper and pencil (and the knowledge
of eg. that the 1. January 1980 was a Tusday) you can start writing
a program which does the same thing as you did on paper. Hint: you could
eg count how many days have elapses since 1. January 1980, divide that
number by 7, ...


I need to view data for a selected week given the week number or date.

Should not be a big problem, once you have the number of the week.
need some controls on not allowing the ball number to go >49 or <0 and
no duplicates.
Where is the problem?

if( ball1int < 0 || ball1int > 49 )
cout << "This is an invalid input. 0 to 49 only\n";

if( ball1int == ball2int ||
ball1int == ball3int ||
ball1int == ball4int ||
ball1int == ball5int ||
ball1int == ball6int ||
ball1int == ball7int )
cout << "You entered a duplicate value for ball 1\n";

You probably will want to enclose the whole ball reading sequence
into a loop, which repeats until a valid set of ball numbers is entered.
bool Valid;

do {
Valid = true; // assume the input will be valid.

// ask user for numbers

// check numbers and set flag 'Valid' to false if the assumption
// of valid input doesn't hold
if( ball1int < 0 || ball1int > 49 ) {
cout << "This is an invalid input for ball 1. 0 to 49 only\n";
Valid = false;
}

....

} until( Valid );

You might also want to enhance this to give the user a chance to cancel
the whole process. But this is up to you.
You might also want to divide the whole thing into functions to make
it better readable. But the principle stays the same: Use a loop
to let the user repeat the input until the input is valid.

the date needs some work on so the user can only enter numbers not
letters.


Turn that around:
Let the user enter characters (eg. as a string) and figure out if this
string can be converted into a number.
The point is: You can't hinder the user to enter letters. Your program
gets control on what has entered only after the user has entered it. But
of course you can react gracefully to it.
There are 2 strategies in C++ to deal with that:
either let the stream operations do the detection and clear up the stream
error state and discard all pending characters or read as string and convert
on your own.
See this newsgroup and search for posts entitled: 'how to convert from string
to number' or something similar. This topic comes up at least 4 times a week.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vilmar Brazão de Oliveira | last post by:
HI, Does anybody have a smartupload sample? thanks, -- Sem mais, ««««««««»»»»»»»»»»»»»» Vlmar Brazão de Oliveira Desenvolvimento Web
43
by: Minti | last post by:
Hi there everybody, I was just wondering that too many people choose to use language like Java because of its architecture independence, this AI is achieved because Java is as such a...
2
by: bobben | last post by:
Hi everybody. I don't know if this is possible, but I am looking for a way to automatically inject code. I would like to fire a Debug.Writeline() automatically when a method is invoked and...
4
by: Michael Grosse | last post by:
I've conquered a very strange behaviour that I cannot account for logically and therefore seek help in this Discussion Group. I'm currently developing 2 applications and intend to use the standard...
5
by: Geoff Jones | last post by:
Hi Does anybody use the Visual Basic Resource Kit? I have a question about it and I've either discovered a bug in it or have a problem with my installation. Geoff
2
by: equalium | last post by:
Hello, this sentence is from the Ajax.Request.prototype function in prototype.js: this.url += (this.url.match(/\?/) ? '&' : '?') + parameters; I understand what it does but I don't know how...
4
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory...
2
by: czi02 | last post by:
does anybody knows how to connect access to visual basic?? I know that this is for access and database but hope that there is someone who could help me just a simple code on how to connect easch...
3
by: czi02 | last post by:
does anybody out there some website for the tutorials of c++. and how to code it. How to make a flowchart and how to solve problem.
1
by: JSievers | last post by:
Hallo. A good friend of me develops web suites, for example his own at: www.augenpunkte.de. As you can see there my friend is blind and also he uses a Braille-line to develop these projects. For...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.