473,770 Members | 5,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("D ate.txt", ios::in); // open file for input
if(!inClientFil e) // 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>>b alls[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(!outClientFi le) // 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\tYo u entered a number not on menu Menu ";
cout << "\n\n\n\nPr ess 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 1927
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
2068
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
8730
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 platform indeed, the code is converted to a byte code and this byte code can be run on any machine which has
2
4717
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 when the method exists. Anybody knows if this is at all possible? Or is any other variant possible ? Is custom attributes a way to go?
4
6168
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 open File Dialog with the code snippet found below. The code snippet is exactly the same in both applications but the behaviour is fundamentally different. In one application when you select adifferent filter from the filter selection group box...
5
1338
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
1466
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 does "/\?/" work. Would it be the same as "this.url.match('?')" ? - What is each slash for? - Is "\?" an escape character?
4
2315
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 as the sample. I have trouble translating those samples to working with data coming from my database, so I am hoping that someone could show me a sample of code that builds a tree from say a dataset. Many controls you can bind to a datasource,...
2
1802
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 other and what is its code and what control am I going to used..
3
1328
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
2543
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 example his own suite at. But he has a big problem to find out the right colours for his pages and so he asked me for a big list with some colour schemes. A hex-colour-value for each part of a page (Text, Links e.g.) So I have had a look at some...
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8887
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.