Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - DOS prompts | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
Zer0wned

Cheep-cheep
Level: 17

Posts: 46/181
EXP: 21472
For next: 3271

Since: 08-16-05
From: Hermosa Beach, CA

Since last post: 30 days
Last activity: 30 days
Posted on 08-31-05 11:48 AM Link | Quote
For learning purposes, I'm making a little DOS program that calculates proper change (how many dimes, nickels, pennies, etc.) from $1. Say something costs 7 cents, it returns as:
3 quarters
1 dimes
1 nickels
3 pennies

Right now I alls have to prevent it from shutting immediately if you double-clicked it in windows is this command at the end, which makes a useless prompt

int k;
cout << "See!? it didn't close!";
cin >> k;

I want it to return to the prompt asking for price in the beginning instead of closing the program or just stalling at a prompt like I made it do. Like a branching prompt:

Exit? y/n
^^--like so, so if I were to enter "n" I'd be brought back to the beginning

If neccessary I can post the source code (it's only like 30 lines)
Dish

Spiny
Level: 38

Posts: 549/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-31-05 12:07 PM Link | Quote
First of all... Console != DOS. There is no reason why you should be coding for DOS, it's a dead OS. In all likelyhood you're coding for windows, albiet commandline.

That aside -- you could accomplish this by putting the main program inside of a loop -- something like:




void DoProgram()
{
//ask for price and calculate and print change here
}

int main()
{
char answer;
do
{
DoProgram();
cout << "Exit? y/n";
cin >> answer;
}while(answer != 'y');

return 0;
}




My code might be a little off as I'm not very familiar with cin/cout (I hate console) -- but it gives the general idea. The Do-While loop will run the contents once, then check to see if they typed 'y' at the final prompt -- if they did, the loop will exit and the program will close. Otherwise the loop will continue, asking for the price and whatever all over again.
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6720/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 08-31-05 12:17 PM Link | Quote
DOS is useful when Windows crashes and you don't want to lose a lot of your stuff.
Zer0wned

Cheep-cheep
Level: 17

Posts: 47/181
EXP: 21472
For next: 3271

Since: 08-16-05
From: Hermosa Beach, CA

Since last post: 30 days
Last activity: 30 days
Posted on 08-31-05 12:17 PM Link | Quote
Yup, that worked, thanks. Now to add bills!

And as for calling it DOS, it's a bad habit, I see that black and white text and that's what comes to mind.

*Repeats "Commandline isn't always DOS" in head*

@Hyperhacker I can't remember one time I've ever managed to save my stuff with DOS... it was always too late T_T


(edited by Zer0wned on 08-31-05 03:21 AM)
FloBo

Koopa
Level: 17

Posts: 85/101
EXP: 20723
For next: 4020

Since: 09-11-04

Since last post: 3 days
Last activity: 13 hours
Posted on 08-31-05 02:54 PM Link | Quote
additionally, you may consider using barts pe-builder or any knoppix-linux to save your data when windows refuses to work... with barts pe, you even have native windows-ntfs support with complete read/write access and support for usb-mounting etc.

so there's no REAL reason to use dos anymore, unless your computer is veeeeeeery old^^
Zer0wned

Cheep-cheep
Level: 17

Posts: 49/181
EXP: 21472
For next: 3271

Since: 08-16-05
From: Hermosa Beach, CA

Since last post: 30 days
Last activity: 30 days
Posted on 08-31-05 08:57 PM Link | Quote
Alright, I finished my program. Now I have it so that you can put any amount you want for cost and amount paid, it will then calculate out the change, and give you the amount of bills/coins needed.

Which brings me to a new question: How can I get it so that when the values=0, I can omit that output? (so I don't get all this quarters= 0, dimes= 0 clutter)

And knoppix linux supports NTFS natively!? Sweet, I was considering adding a linux OS to my computer (and learning how to use it ), but most of my stuff is in NTFS, which would kind of ruin it for me. *googles knoppix-linux*




(edited by Zer0wned on 08-31-05 12:16 PM)
Dish

Spiny
Level: 38

Posts: 550/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-31-05 09:17 PM Link | Quote
if(number_of_quarters != 0) cout << number_of_quarters << " quarters.";
Zer0wned

Cheep-cheep
Level: 17

Posts: 50/181
EXP: 21472
For next: 3271

Since: 08-16-05
From: Hermosa Beach, CA

Since last post: 30 days
Last activity: 30 days
Posted on 08-31-05 09:25 PM Link | Quote
Disch, you reek of awesome. Thanks again. I'm done with questions for a while *goes back to the tutorials*

(btw, the text is fairly readable on this background, right? it seemed like the most readable color)
Edit: Oh well...


(edited by Zer0wned on 08-31-05 12:34 PM)
Dish

Spiny
Level: 38

Posts: 551/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-31-05 09:30 PM Link | Quote
No -- get rid of that background. That's a terrible background for a post layout.
FloBo

Koopa
Level: 17

Posts: 86/101
EXP: 20723
For next: 4020

Since: 09-11-04

Since last post: 3 days
Last activity: 13 hours
Posted on 08-31-05 11:58 PM Link | Quote
Erm... knoppix supports read-only NTFS. write-mode is still quite buggy. Only barts windows pe can write ntfs properly... but you may just convert your partitions to fat32. this works very well under linux^^
Wopple

Red Goomba
Level: 8

Posts: 2/41
EXP: 2026
For next: 161

Since: 09-03-05

Since last post: 8 days
Last activity: 8 days
Posted on 09-03-05 11:51 PM Link | Quote
Originally posted by HyperHacker
DOS is useful when Windows crashes and you don't want to lose a lot of your stuff.


A Linux boot is more usefull =-P
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - DOS prompts | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.059 seconds.