Solved

Converting COUT to MessageBox??

Posted on 1998-07-21
1
433 Views
Last Modified: 2006-11-17
Hi!

I know how to do the following in VC++, but I'm finding it's a little different using Borland's Turbo C++ 4.5 for Windows!

Please take a look at the following code. What I want to do it take the last two COUT lines and place them into a MessageBox.

In VC++, I use CString to declare tempstring (example: CSTRING tempstring). I then initialize tempstring with the MB message (example: "You entered: " + m_LoginName;). How do I get a MessageBox to do this with Borland's little, outdated compiler (I have to use it for school)?

The code:

#include <iostream.h>
int main()
{
int Seconds = 0;

cout << "How much whipped cream is in the can (percentage)? " << flush;
float Balance;
cin >> Balance;

float WhippedCream = Balance * .50;

      while (Balance > WhippedCream)
            {
            ++Seconds;
            Balance *= .98;
            }

cout << "\nIt will take " << Seconds << " seconds to empty half of the ";
cout << "\nremaining whipped cream." << endl;

return 0;
}

Hi!

I know how to do the following in VC++, but I'm finding it's a little different using Borland's Turbo C++ 4.5 for Windows!

Please take a look at the following code. What I want to do it take the last two COUT lines and place them into a MessageBox.

In VC++, I use CString to declare tempstring (example: CSTRING tempstring). I then initialize tempstring with the MB message (example: "You entered: " + m_LoginName;). How do I get a MessageBox to do this with Borland's little, outdated compiler (I have to use it for school)?

The code:

#include <iostream.h>
int main()
{
int Seconds = 0;

cout << "How much whipped cream is in the can (percentage)? " << flush;
float Balance;
cin >> Balance;

float WhippedCream = Balance * .50;

      while (Balance > WhippedCream)
            {
            ++Seconds;
            Balance *= .98;
            }

cout << "\nIt will take " << Seconds << " seconds to empty half of the ";
cout << "\nremaining whipped cream." << endl;

return 0;
}

Thanks!

Mike Wonch
0
Comment
Question by:MWonch
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1168248
The following code works with both compilers.

char szBuf[256];

::wsprintf(szBuf, "\nIt will take %d seconds to empty half of the \nremaining whipped cream.", Seconds);

::MessageBox(NULL, szBuf, "title", MB_OK);
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question