473,799 Members | 2,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ assignment problems :(

9 New Member
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];

SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 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;

SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 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)
{
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 196);
cout << "+----------------------------------------------------+" << endl;
cout << "| Error Opening File, Closing Program |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
exit(1);
}


if (menuoption1 <= 1)
{
if (date == datecheck)
{
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 252);
cout << "+----------------------------------------------------+" << endl;
cout << "| Option 'Match Schedule' Selected |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;

SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 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;

SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 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=fge tc(inputdata))! =EOL)
while(fgets(tem p,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);
// }
//}



SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 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
{

SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 252);
cout << "+----------------------------------------------------+" << endl;
cout << "| Option 'Match Schedule' Selected |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;


SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 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 2001

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

Similar topics

23
3240
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 there are no assignment expressions in Python, I have to use a temp var. That's a little more messy, but bearable:
8
6448
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 messages are presented after the source code.
34
7188
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
2026
by: subramanian | last post by:
Consdier the following program: #include <stdio.h> struct typeRecord { int id; char str; } records = { {0, "zero"}, {1, "one"},
12
6255
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: gcc version 4.0.1 (Apple Inc. build 5465). thanks for the help. summary of compile error: --------------------------------------- cpp.C:4: error: non-static const member 'const unsigned int A::u',
4
3283
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 a temporary object "temp" in this sample, and assignment is made on a to temp ar first. Even if there is exception, the current this object's state is not corrupted.
7
2025
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 similarity (or even sequentiality to allow effective journey planning throughout a day). I've currently looked at something called SPA - Simple Parallel Assigning which works out the cost of assigning each node to its nearest and next nearest outlet, and...
1
3324
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. Assignment Purposes This assignment aims to • Introduce practical problems to students to implement a dynamic web page on a web server.
1
2933
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 to  Introduce practice problems to students to implement object oriented concepts and GUI programming by using Java programming language.  Makes students to implement specific classes with relevant methods for a specific problem  Test the...
0
9689
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
10495
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...
1
10248
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
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
7573
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
5469
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
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.