473,406 Members | 2,369 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,406 software developers and data experts.

C++ assignment problems :(

okay, ive been going okay on my assignment, but ive just run into a problem.

i need to read a file into my program, the data from the file is to be read, and then randomised to produce "match data" for some matches.

im not too sure on how to do this.

i have tested reading the file in and outputting it onto the program, but it seems to read the data vertically rather than line by line :S which causes even more of a problem.

my code.

// ************, Software Development
// Unit: 8, Programming and Concept

#include <iostream.h>
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <fstream.h>
#include <stdlib.h>
#include <conio.h>


void main (void)

{




int date;
int datecheck = 01012007;
int datenum = 0;
int menuoption1 = 0;
int menuoption2 = 0;
int print1 = 0;

FILE *inputdata;
char temp[200];

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 252);


while (datenum <= 0)
{
cout << "+----------------------------------------------------+" << endl;
cout << "| Please Enter Date |" << endl;
cout << "| Format: ddmmyyyy |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << " --> ";
cin >> date;

cout << "+----------------------------------------------------+" << endl;
cout << "| Is Date Correct? |" << endl;
cout << "| No = 0, Yes = 1 |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << " --> ";
cin >> datenum;



}




cout << "+----------------------------------------------------+" << endl;
cout << "| Date Entered Successfully |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 46);

cout << "+----------------------------------------------------+" << endl;
cout << "| Welcome |" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| Please Select An Option: |" << endl;
cout << "| |" << endl;
cout << "| 1. Match Schedule (default) |" << endl;
cout << "| 2. Input Match Results |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << " --> ";
cin >> menuoption1;

inputdata=fopen("D:\\input data.txt", "rt");


if(!inputdata)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 196);
cout << "+----------------------------------------------------+" << endl;
cout << "| Error Opening File, Closing Program |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
exit(1);
}


if (menuoption1 <= 1)
{
if (date == datecheck)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 252);
cout << "+----------------------------------------------------+" << endl;
cout << "| Option 'Match Schedule' Selected |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 162);

cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| |" << endl;
cout << "| Access Granted |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 226);

cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| |" << endl;
cout << "| Todays Match Schedule is as follows: (tbs) |" << endl;

//while((temp=fgetc(inputdata))!=EOL)
while(fgets(temp,200,inputdata) !=NULL)
cout << temp;

cout << endl << endl;



cout << "| |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
//cout << "| File to be Printed? (tbs) |" << endl;
//cout << "| No = 0, Yes = 1 |" << endl;
//cout << "+----------------------------------------------------+" << endl;
//cout << " --> ";
//cin >> print1;

//if (print1 == 1)
//{
// ofstream print("lpt3");
// if(!print)
// {
// cout<<"could not open printer\n";
// exit(1);
// }
//}



SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 46);

cout << "+----------------------------------------------------+" << endl;
cout << "| Welcome |" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| Please Select An Option: |" << endl;
cout << "| |" << endl;
cout << "| 1. Input Match Results |" << endl;
cout << "| |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << " --> ";
cin >> menuoption2;

cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| Match Result Input |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;


}

else
{

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 252);
cout << "+----------------------------------------------------+" << endl;
cout << "| Option 'Match Schedule' Selected |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;


SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 196);

cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| |" << endl;
cout << "| Access Denied |" << endl;
cout << "+----------------------------------------------------+" << endl;

}
}

else
{ cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| Match Result Input |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| test |" << endl;

}



fclose (inputdata);

}

of course, the code isnt quite complete anyways, but i need to get this reading and randomising sorted... the rest should fall into place.

maybe i should read the file into a seperate function?? i dont know... help lol
Nov 10 '06 #1
0 1972

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
8
by: Gary Schnabl | last post by:
What might the problems be in the following code?: The problems occur at these two lines: <snippage> p.L2 = {5,6,10,12,255}; <snippage> q={{0,0,5,6,128},{5,6,-10,6,128},1}; <...> The error...
34
by: Chris | last post by:
Is there ever a reason to declare this as if(*this == rhs) as opposed to what I normally see if(this == &rhs) ?
5
by: subramanian | last post by:
Consdier the following program: #include <stdio.h> struct typeRecord { int id; char str; } records = { {0, "zero"}, {1, "one"},
12
by: hweekuan | last post by:
hi, it seems i can't assign the const variable u in class A, one way to solve the problem may be to build a copy constructor. however, why does C++ or vector class not like this code? my g++ is:...
4
by: George2 | last post by:
Hello everyone, The following swap technique is used to make assignment operator exception safe (means even if there is exception, the current object instance's state is invariant). It used...
7
by: IanWright | last post by:
I'm trying to come up with an effective assignment algorithm to allocate nodes to a nearest outlet, where each node should be have a time slot checked against the already allocated nodes for...
1
by: khalfan | last post by:
Assignment Objectives: The objective of this assignment is to design and develop a dynamic web site application with the use of ASP to create a database and manipulate the information. ...
1
by: khalfan | last post by:
Assignment Objectives: The objective of this assignment is to implement java programs with major object oriented concepts and applet with event handling. Assignment Purposes This assignment aims...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.