Solved

Converting COUT to MessageBox??

Posted on 1998-07-21
1
435 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ question 3 75
How to print into std::string like sprintf using C++11? 12 125
C++ help/ Toy problem 19 56
C++ statement T∗ begin(Vector<T>& x) 5 15
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

697 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