?
Solved

Converting COUT to MessageBox??

Posted on 1998-07-21
1
Medium Priority
?
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

765 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