Help - Search - Members - Calendar
Full Version: Sham + C++ =*fall down go boom*
Krazy Letter Forums > The Modern World > Tech Help and Advice
Sham
I need some help with my code here. I am using file in out now, and it is not working as I would want it to. I have mess with the code a bit so if you see some funky stuff that is why.

It will save the item to the (item_name)file fine. But it wont save anything to the "database" or "maindat"...






#include
<iostream>

#include <fstream>

#include <string.h>

using namespace std;





ofstream outfile;

ifstream infile;

void auction_item(), auction_bid(), auctionsave(int ta), auctionsavepre(int ta), totalauctions(int ta), auctionread(int ta);



char item_name[25], item_description[250];

char total[25], maindat[25];

float item_price;

int ta;

int choice, itemammount;



int main()

{







cout <<
"Welcome to auctioneer, an auctioning program by Sam Evertson.\n";

cout <<
"This program will accept any auctions that you the end user will input.\n";

cout <<
"Once you input them it will store it onto a database and allow other users\n";

cout <<
"to bid on it.\n";

cout <<
"First please tell me if you are auctioning an item, or bidding on one.\n";

cout <<
"Enter (1) for auctioning an item, and (2) for bidding.\n";

cin >> choice;

switch (choice)

{

case 1:

auction_item();

break;

case 2:

auction_bid();

break;

}

return 0;

}



void auction_item()

{

cin.ignore();

cout <<
"You have chosen to auction an item, and are putting it into the " << maindat << " database, please reply with the items name. (Such as: Model Plane, or Ford F50) (Max of 25 Characters).\n";

cin.getline(item_name,25);

cout <<
"Now please briefly describe the item. (Max of 250 characters).\n";

cin.getline(item_description,250);

cout <<
"Now please state the price. (Please use a format of 0.00) (Leave out all other symbols such as Doller signs ($).\n";

cin >> item_price;

cin.ignore(90,
'\n');

outfile.open(item_name,ios::out);

if (outfile)

{

outfile << item_name << endl;

outfile << item_description << endl;

outfile << item_price << endl;

outfile.close();

}

else

{

cout <<
"I am sorry, but the file failed to open.\n";

}





auctionread(ta);

auctionsavepre(ta);

auctionsave(ta);





cin.get();

cout <<
"You have successfully stored the data of your auctioned item into the database, here is the info that you gave us:\n";

infile.open(item_name,ios::in);

if (infile)

{

cout <<
"Item Name: ";

infile.getline(item_name, 25);

cout << item_name;

cout <<
"\n";

cout <<
"Item Description: ";

infile.getline(item_description, 250);

cout << item_description;

infile >> item_price;

cout <<
"\n";

cout <<
"Item Price: $";

cout << item_price;

infile.clear();

cout <<
"\n";





}

else

{

cout <<
"We have failed to open up the Auction Items file.\n";

}

}





void auction_bid()

{

cout <<
"You have stated that you wish to bid on an item, we currently have "<< ta << " item(s) in our database.\n";

}

void auctionsavepre(int ta)

{

infile.open(
"database",ios::in);

if (infile)

{

ta++;

infile.clear();

}

else

{

cout <<
"We could not open the database\n";

}

}

void auctionsave(int ta)

{

outfile.open(
"database",ios::out);

if (outfile)

{

outfile << ta;

outfile.clear();

}

else

{

cout <<
"We could not open the database\n";

}

}

void auctionread(int ta)

{

infile.open(
"database",ios::in);

if (infile)

{

infile >> ta;

infile.clear();

}

else

{

cout <<
"We could not open the database\n";

}

}

Hollow
Wow... um... global vars...

Anyway, playing around with C++ again eh?
Sham
Yea I got a job, and have been busy at school. Now I left the job and school is winding down for xmas break, so I am gonna start coding again. I know I am still a beginner at it., but.. i wanna get better.
Joe
I miss C++, I went to a tech camp and learned basic C++ and now I can't put it to use since I use a mac. Boot camp isn't an option for my Macbook Pro cause of the lack of HD space.
krt
http://www.maczoop.com/ doesn't look too bad

And why not use C#, so much easier - so little messing around with the low level crap

I would have expected that to be the thing around here with all you M$ fanboys! For once, Microsoft do something good (.NET after spending an estimated 80% if their development budget on it) and it is not embraced here as much as I would have thought.
Hollow
QUOTE(krt @ Jan 2 2007, 03:48 AM) *
http://www.maczoop.com/ doesn't look too bad

And why not use C#, so much easier - so little messing around with the low level crap

I would have expected that to be the thing around here with all you M$ fanboys! For once, Microsoft do something good (.NET after spending an estimated 80% if their development budget on it) and it is not embraced here as much as I would have thought.

C# and .NET is good and all, but it's a fucking pisser if you want to go cross-platform.
krt
http://www.mono-project.com/
http://www.cross-platform.net/

I have no problems with it, a bit more work is worth the benefits of .NET
myncknm
.NET is just a rip-off of Sun's Java. tongue.gif
krt
Yeh, I noticed that lot when I started learning C#. But regardless, it is great and better than Java in my opinion.
Hollow
QUOTE(krt @ Jan 2 2007, 04:35 PM) *
http://www.mono-project.com/
http://www.cross-platform.net/

I have no problems with it, a bit more work is worth the benefits of .NET

I know of Mono. Mono only supports the 1.1 .NET framework, outdated. The newest version only has an incomplete implemention of 2.0 to work with. The framework is at version 3.0 or something now. Useless. I rather Java over C# any day.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.