[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Converting COUT to MessageBox??

Posted on 1998-07-21
1
Medium Priority
?
440 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…
Suggested Courses

834 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