|
Hello everyone!! Ok I got the bool loop done....now my only question is how do I get my program to repeat until 'E' is entered....I don't know if I'm supposed to put the void functions in the other.....PLease Help.....
#include <iomanip>
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void PrintInstructions (float&, string&, float&);
void GetSingleTransInfo(char&, float&);
void ProcessDeposit (float, float, float&);
void ProcessCheck (float, float, float&, float&);
void PrintFinalTotals ();
void PrintBlankLines (int);
const float CHECK_CHARGE = .15f;
const float DEPOSIT_CHARGE = .10f;
const float ONE_TIME_CHARGE = 5.00f;
int main ()
{
string month;
float balance;
float transAmount;
char transCode;
float charge;
float currentBalance;
PrintInstructions (balance, month, charge);
GetSingleTransInfo (transCode, transAmount);
if (transCode == 'C')
{ ProcessCheck(transAmount, balance, currentBalance, charge);
}
if (transCode == 'D')
ProcessDeposit(transAmount, balance, currentBalance);
else
cout <<" This is the end of the month\n";
return 0;
}
void PrintInstructions(/*out*/ float& beginBalance, /*out*/ string& month, /*out*/ float& charge)
cout << "Please enter the month to be balanced: ";
cin >> month;
cout << endl;
cout << "Please enter the beginning balance for the month: ";
cin >> beginBalance;
below500 = (beginBalance < 500.00);
if (below500)
{
charge = ONE_TIME_CHARGE;
}
PrintBlankLines (3);
system ("pause");
system ("cls");
void GetSingleTransInfo (/*out*/ char& code, /*out*/ float& amount)
PrintBlankLines (4);
cout << " Select form the following transactions:\n\n";
cout << " C / c - for a check\n";
cout << " D / d - for a deposit\n";
cout << " E / e - for end of the month\n\n";
PrintBlankLines (3);
cout << "Enter you transaction choice: ";
cin >> code;
code = toupper (code);
cout << endl;
while (code != 'C' && code != 'D' && code != 'E')
{
cout << "\nError.....you must select a code from above\n\n";
cout << "Please enter a new transaction code: ";
cin >> code;
cout << endl;
code = toupper (code);
}
if (code == 'C' )
{
cout << "Please enter transaction amount: ";
cin >> amount;
cout << endl;
}
if (code == 'D')
{
cout << "Please enter transaction amount: ";
cin >> amount;
cout << endl;
}
system ("pause");
system ("cls");
}
//***************************************************************************************************************
void ProcessCheck(/*in*/ float amount, /*in*/ float balance,
/*out*/ float& currBalance, /*out*/ float& charge)
// Purpose: Deduct amount of check from balance....apply charges if balance falls below zero by
// cause of check. Apply charge if balance falls below $500.00.
// Pre:
// Post:
{
bool below500;
currBalance = balance - amount;
below500 = (currBalance < 500.00);
cout << " Check Transaction\n\n\n";
cout << fixed << setprecision (2) << endl;
cout << "Check Amount: " << amount << endl;
cout << "Current Balance: " << currBalance << endl;
cout << "Check Charge: " << CHECK_CHARGE << endl;
if (below500)
{
charge = ONE_TIME_CHARGE;
cout << "One Time Below $500.00 charge: " << charge << endl;
}
GetSingleTransInfo (transCode, transAmount);
system ("pause");
system ("cls");
}
//***************************************************************************************************************
void ProcessDeposit (/*in*/ float amount, /*in*/ float balance,
/*out*/ float& currBalance)
{
currBalance = balance + amount;
cout << " Deposit Transaction\n\n\n";
cout << fixed << setprecision (2) << endl;
cout << "Deposit Amount: " << amount << endl;
cout << "Current Balance: " << currBalance << endl;
cout << "Deposit Charge: " << DEPOSIT_CHARGE << endl;
}
Thanks in advance!!
Autumn
|
|
|
|
|
while((_getch()!="e") || (_getch()!="E"))
{
blah blah blah;
}
would be the easiest way of getting it to run until E is pressed.
|
|
|
|
|
That's helps alot Carrie....I jus don't know where to put it....if I put it in the main....it get a never ending loop!!! Thanks
Autumn
|
|
|
|
|
shouldn't that be && ? _getch() will always != 'e' || != 'E'.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
now Christian...dont' go off confusing me tonight!!! I hope your Thansgiving was well.... So how/ where in my program is this loop supoosed to be. It will run through once but that is all... Do I need to move things around? I'm lost please help!!
Autumn
|
|
|
|
|
Place the loop around all of your code that you want to repeat.
Also change the loop from above to this.
char ch = _getch();
while (ch != 'e' && ch != 'E')
{
...
}
because the way it is written above it will call getch two separate times and remove two separate characters.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
/me hangs her head
Yeah, you're right. It was made after midnight though so I think I'm excempt from the public flogging
|
|
|
|
|
Well, I can only think of one person who was perfect, and look what they did to Him....
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Hi,
We have a problem with corrupted addresses when sending a pointer in the LPARAM argument of ::SendMessage() to another application.
Roughly, the code looks like this:
TCHAR g_szName[] = _T("abcd");
VOID SendName(HWND hWnd)
{
::SendMessage(hWnd, WM_USER, 0, (LPARAM)g_szName);
}
In the debugger, we can have g_szName equal to for instance 0x0e006719 before the ::SendMessage() call. But in the receiving application the higher bits are cleared so we only have 0x00006719 there, which isn't likely to contain the string we want to use...
Any idea why this is? I can assure you it's annoying and it feels like I've done exactly this successfully at least a thousand times before, not to mention WM_SETTEXT , which is practically the same, only it works...
I appreciate any pointers on this subject.
Thanks!
/Johann Gerell
|
|
|
|
|
Pointers do not generally marshall across process boundaries.
You will need to allocate memory using the GlobalAlloc function in order to pass the data between your two applications.
WM_SETTEXT has some special processing in it to marshall your pointers for you. I think the same goes with WM_GETTEXT and possibly a few other messages.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Paul Watt wrote:
You will need to allocate memory using the GlobalAlloc function in order to pass the data between your two applications.
I can't with pride use a function documented as being there to provide compatibility for 16 bits apps. And, are you really sure it does what it promises? Since Win32 doesn't have separate local and global heaps (only local, right?), how could that function allocate global heap?
Pointers do not generally marshall across process boundaries.
Yes, of course - I know that. Normally. But last night/morning at 5.30 AM, after long hours preparing for a first press demo of our product some hours later, neither me or my co-worker accepted this reason (happens way too often).
I told him (with an enlightened smile) "...but each process has its own address space and pointers from one doesn't translate to the other." Upon which he (of course) replied "Of course." But did we accept that? No. At that hour without any sleep, things should just work...
We already use WM_COPYDATA for IPC and that's the way to here also, but this morning I could have sworn there were no such thing as WM_COPYDATA...
Thanks anyway!
/Johann Gerell
|
|
|
|
|
I love reason messages like this. Every programmer worth his weight in salt has done stuff like this. It brings back so many "happy" memories.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Paul Watt wrote:
You will need to allocate memory using the GlobalAlloc function in order to pass the data between your two applications.
That is incorrect. The local/global distinction is a holdover from Win16. From MSDN:Memory objects allocated by GlobalAlloc and LocalAlloc are in private, committed pages with read/write access that cannot be accessed by other processes. Memory allocated by using GlobalAlloc with GMEM_DDESHARE is not actually shared globally as it is in 16-bit Windows. This value has no effect and is available only for compatibility. Applications requiring shared memory for other purposes must use file-mapping objects. I wish it were still as easy as calling GlobalAlloc.
--Mike--
Friday's GoogleFight results: Britney Spears 2,190,000 - Erica Weichers 23
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Use WM_COPYDATA to send data between applications.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Definately. That's what we've been doing and should without question continue to do. Early morning hours can do much damage to ones brain.
Thanks for the input!
/Johann Gerell
|
|
|
|
|
Johann Gerell wrote:
Early morning hours can do much damage to ones brain.
I couldn't agree more. Happens to me at least 5 times a day!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
What? Data between two applications?
This means inter-communication, so use Dynamic Data Exchange (DDE).
ZARZOR13
|
|
|
|
|
Has anyone developed a template class that emulates the VB For Each element In group ... Next.
where element is an object
and group is a collection of those objects
Gary Kirkham
A working Program is one that has only unobserved bugs
|
|
|
|
|
Me Think STL do this! vector, list , map, ...
Max.
|
|
|
|
|
Like Max mentioned, STL has a for_each template function. Look it up in MSDN.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Hey Guys,
I have a working MFC application (that I developed). I want to make the same work as a command line application (without bringing the GUI on screen). Meaning, the user should be able to use it just like a command, for example
MyMFCApplication -D -F *.txt
Where -D would be for download and -F is for file(s) OR any other option that I want later.
Could you guys please help me in understanding if this is possible at all?
If it is how to go about it so that I can have both modes.
Thanks
-Mahesh Shimpi
Ideas multiply by sharing!!
|
|
|
|
|
What you need to do is to look in your CWinApp derived class, and there scan the command line text, you'll need to run that way only if flags ( or a flag ) are provided, then simply do what you want to, and return without starting up your window.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
|
Porting problem???
I have a set of defines:
#define PROT_NACK_NONE 0
#define PROT_NACK_BYE 1
…
…
…
#define PROT_NACK_BAD_PROT 3
________________________________
And I also have a typedef structure:
typedef struct reject_s
{
short int rejectCode;
const char *message;
} reject_t;
reject_t *m_rejectTable;
_________________________________
I than implement my function which uses the above:
void CMessageProtocol::setRejectTable( )
{//private:
static reject_t reject[]=
{
{ PROT_NACK_NONE, ""},
{ PROT_NACK_BYE, "Bye"},
{ PROT_NACK_NO_MORE_CON, "No More Connection availiable"},
{ PROT_NACK_BAD_PROT, "Protocol version not supported"},
{ PROT_NACK_BAD_ENC, "Encryption version not supported"},
{ PROT_NACK_BAD_APP, "Application refused"},
{ PROT_NACK_BAD_LOG_PASS, "Invalid Login or password"},
{ PROT_NACK_BAD_MSG, "Invalid Message format"},
{ PROT_NACK_DEFAULT, "Error"},
{ 0, 0}
};
m_rejectTable = reject;
}
The above has been complied and runs under Microsoft Visual Studio 6
I am now attempting to implement this into a .NET library, that has a bunch of __gc classes, when I now attempt to convert using the following syntax:
typedef __nogc struct reject_s
{
const char message;
short int RejectCode;
} reject_t;
reject_t* m_rejectTable;
typedef __nogc struct encrypting_s
{
char crypto;
char * encryptingName;
unsigned char cypher[2];
} encrypting_t;
encrypting_t* m_encryptingTable;
when I attempting to implement the __gc class method that use’s the above:
void GEMBrokerMessengerProtocol::CGEMMessageProtocol::setRejectTable()
{
static reject_t reject[]=
{
{ PROT_NACK_NONE, ""},
{ PROT_NACK_BYE, "Bye"},
{ PROT_NACK_NO_MORE_CON, "No More Connection availiable"},
{ PROT_NACK_BAD_PROT, "Protocol version not supported"},
{ PROT_NACK_BAD_ENC, "Encryption version not supported"},
{ PROT_NACK_BAD_APP, "Application refused"},
{ PROT_NACK_BAD_LOG_PASS, "Invalid Login or password"},
{ PROT_NACK_BAD_MSG, "Invalid Message format"},
{ PROT_NACK_DEFAULT, "Error"},
{ 0, 0}
};
m_rejectTable = reject;
}
I get the following error under Visual Studio C++.NET
c:\Documents and Settings\mdyer\My Documents\Visual Studio Projects\CGEMBroker\GEMBrokerMessengerProtocol.cpp(22): error C2440: 'initializing' : cannot convert from 'int' to 'GEMBrokerMessengerProtocol::CGEMMessageProtocol::reject_t'
c:\Documents and Settings\mdyer\My Documents\Visual Studio Projects\CGEMBroker\GEMBrokerMessengerProtocol.cpp(22): error C2689: Initializing 'reject' : this form of non-aggregate initialization requires a unary constructor
I am very curious as to why I am having these compile errors under .NET and not under my previous compile of Visual Studio 6???? Very lost here????
|
|
|
|
|
I'd suggest asking this in the MC+ forum if you're trying to create a .NET library. I'd also recommend const int over #define.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|