What's Here?
- Members: 149,631
- Replies: 506,753
- Topics: 79,851
- Snippets: 2,666
- Tutorials: 706
- Total Online: 2,066
- Members: 79
- Guests: 1,987
|
A simple calculating program used to mock a checkbook.
Shows simple but good use of "fstream" and "switch" statement.
|
Submitted By: ihatepikingnames
|
|
Rating:
 
|
|
Views: 1,890 |
Language: C++
|
|
Last Modified: October 31, 2006 |
Instructions: Just complile Money.cpp. Don't forget to put the header in the include path.
PS: you could easily make the headers part of the code... its just not my style. |
Snippet
/*Money! v1.0 by Boomer 2006.10
underscoredot@yahoo.com*/
//Money.cpp (save as so)
#include <iostream> //<--*
#include <fstream> // *
using namespace std; // ***Good call Xing,
#include <add> // * I'm just lazy.
#include <sub> //<--*
void add(); //in Add.h
void sub(); //in Sub.h
enum BOOL { FALSE, TRUE };
typedef unsigned short int USHORT;
USHORT menu();
int main()
{
BOOL exit = FALSE;
for (;;)
{
USHORT choice = menu();
switch(choice)
{
case (1):
Add();
break;
case (2):
Sub();
break;
case (3):
exit=TRUE;
break;
default:
cout << "Please select again!\n";
break;
} // end switch
if (exit)
break;
} // end forever
return 0;
} // end main()
USHORT menu()
{
USHORT choice;
cout << "\n **** Money! ****\n\n";
cout << "(1) Add $$.\n";
cout << "(2) Subtract $$.\n";
cout << "(3) Exit.\n\n";
cin >> choice;
return choice;
}
//****************************************************
//add.h (save as so)
float Option(float A, float B){return A+B;}
void Add()
{
char RUSure;
float numA, numB, numC;
ifstream datain ( "MoneybyBoomer.txt" );
datain>> numA;
cout<< "You currently have $"<< numA <<"\n";
restart: //for goto statement
cout<< "How much would you like to add?" <<"\n";
cin>> numB;
cout << '\n' << "Is this the right amount? (Y)es or (N)o. ";
cin >> RUSure;
while(RUSure == 'y')
{
numC = Option(numA, numB);
ofstream dataout ( "MoneybyBoomer.txt" );
dataout<< numC;
dataout.close();
datain>> numC;
cout<< "Well shit, now you have $" << numC << "!" << "\n";
break;
}
while(RUSure !='y'){goto restart;}
}
//*****************************************************
//sub.h (save as so)
float Boption(float C, float D){return C-D;}
void Sub()
{
char RUSure;
float numA, numB, numC;
ifstream datain ( "MoneybyBoomer.txt" );
datain>> numA;
cout<< "You currently have $"<< numA <<"\n";
restart: //for goto statement
cout<< "How much would you like to Subtract?" <<"\n";
cin>> numB;
cout << '\n' << "Is this the right amount? (Y)es or (N)o. ";
cin >> RUSure;
while(RUSure == 'y')
{
numC = Boption(numA, numB);
ofstream dataout ( "MoneybyBoomer.txt" );
dataout<< numC;
dataout.close();
datain>> numC;
cout<< "Well shit, now you have $" << numC << "!" << "\n";
break;
}
while(RUSure !='y'){goto restart;}
} //end sub() //end add()
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|