Solved

Converting COUT to MessageBox??

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now