Looking for advice on programming

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Looking for advice on programming

Post by zodiac976 »

I might post it once I am done with it. I need to do some
more error checking and stuff :).

The ATM sim is basically just the menu but the login could
be somewhat like the card reader in a way.

You could also use it for like keeping up with your own budget
and stuff ;P because it constantly updates the balance of course
I am not sure how it would act if the power went out or the
program stopped all of a sudden.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Looking for advice on programming

Post by dandymcgee »

programmerinprogress wrote:well you could just use an fstream to a file on the floppy disk right?

AFAIK streams are pretty indescrimiate of what you're reading from/writing too, just as long as you provide the correct information, but saying that, I've never tried it, so I am somewhat speculating :lol:
You know, I've never tried fstream anywhere but the project's folder but it should work.

EDIT: It works! ;)

main.cpp

Code: Select all

#include <iostream>
#include <fstream>

using namespace std;

int main() {

    string text = "I wonder if this is going to write itself to the floppy disk?!";

    ofstream fileOut;

    fileOut.open("A:\\account.txt");

    while( !fileOut.is_open() ) {
        cout << "Insert floppy disk in drive A: and press ENTER to continue...\n";
        cin.get();
        fileOut.open("A:\\account.txt");
    }

    fileOut << text;
    fileOut.close();

    cout << "Successful write!\n";
    cin.get();

    return 0;
}
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Looking for advice on programming

Post by zodiac976 »

dandymcgee wrote:
programmerinprogress wrote:well you could just use an fstream to a file on the floppy disk right?

AFAIK streams are pretty indescrimiate of what you're reading from/writing too, just as long as you provide the correct information, but saying that, I've never tried it, so I am somewhat speculating :lol:
You know, I've never tried fstream anywhere but the project's folder but it should work.

EDIT: It works! ;)

main.cpp

Code: Select all

#include <iostream>
#include <fstream>

using namespace std;

int main() {

    string text = "I wonder if this is going to write itself to the floppy disk?!";

    ofstream fileOut;

    fileOut.open("A:\\account.txt");

    while( !fileOut.is_open() ) {
        cout << "Insert floppy disk in drive A: and press ENTER to continue...\n";
        cin.get();
        fileOut.open("A:\\account.txt");
    }

    fileOut << text;
    fileOut.close();

    cout << "Successful write!\n";
    cin.get();

    return 0;
}
I use file streaming a lot on all my projects for saving data.
By the way, using this:

ifstream file("test.txt");

has the same effect as:

ifstream file;
file.open("test.txt");

Just saves you an extra line if you didn't know that already.

EDIT: some people say this line is bad to use:
while(!file.eof());
{
}

I use it anyways and don't have problems with it and you can
stick an if statement in there like:

if("string variable".empty() == true)
{
break;
}

Will keep it from inserting an empty line at the end.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Looking for advice on programming

Post by dandymcgee »

zodiac976 wrote:I use file streaming a lot on all my projects for saving data.
Me too, but I've never tried writing to a floppy before. I wasn't 100% sure if FAT would make anything different, although I didn't think it would. Turns out it works just the same.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
programmerinprogress
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Wed Oct 29, 2008 7:31 am
Current Project: some crazy stuff, i'll tell soon :-)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++!
Location: The UK
Contact:

Re: Looking for advice on programming

Post by programmerinprogress »

Yeah, I mean I was pretty sure it would work, but I never tried it, it's actually quite a cool representation of an ATM card ;)


As for file streams, they know nothing about the application or purpose of the data, they just take it in or send it out to the specified file, very clever stuff indeed :D
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D

I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Looking for advice on programming

Post by zodiac976 »

I got to looking at my ATM simulator(new version) again
and it is funny how you make something, look at it after
it is done then you realize why in the world did I do it this
way or why didn't I do this instead :lol:.
Post Reply