5 Replies - 6395 Views - Last Post: 25 March 2011 - 05:46 AM Rate Topic: -----

#1 xkaijinx  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 09-March 11

Message Box / Input Box ?

Posted 23 March 2011 - 12:40 PM

I wrote the below code from a textbook, and after I run the program it compiles it right away without showing the actual data.

I googled several sites, not sure how to correctly write a "message box" and also wanted to see how to write an "inputbox" I'll post the code below anyways just to show.

 #include <iostream> 
using namespace std; 
int main()
{
int value1 = 9;
int value2 = 3; 
int value3 = 10; 
int answer1, answer2, answer3; 
int answer4, answer5, answer6; 

answer1 = value1 * value2 + value3; 
cout << "Answer 1: " << answer1 << endl; 

answer2 = value1 * (value2 + value3); 
cout << "Answer 3: " << answer2 << endl; 

answer3 = value1 + value2 - value3; 
cout << "Answer 3: " << answer3 << endl; 

answer4 = value1 + (value2 - value3); 
cout << "Answer 4: " << answer4 << endl; 

answer5 = value1 + value2 * value3; 
cout << "Answer 5: " << answer5 << endl; 

answer6 = value3 / value2; 
cout << "Answer 6: " << answer6 << endl; 

return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Message Box / Input Box ?

#2 xkaijinx  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 09-March 11

Re: Message Box / Input Box ?

Posted 23 March 2011 - 01:15 PM

Also wanted to ask why this is just running through without displaying the correct information. I would think that the below code should display the information appropriately however it does not.

 cout << "Text here" << endl; 

Was This Post Helpful? 0
  • +
  • -

#3 Derek++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-March 11

Re: Message Box / Input Box ?

Posted 23 March 2011 - 04:31 PM

Add
cin.get();
before return 0 and the program will stay open until you press enter.

As for the "input box", I assume you mean cin?

#include <iostream>

int main()
{
    int data;

    std::cout << "Enter a number: ";
    std::cin >> data;
    std::cout << "Your number is: " << data << '\n';

    std::cin.get();

    return 0;
}

This post has been edited by Derek++: 23 March 2011 - 04:40 PM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Message Box / Input Box ?

Posted 23 March 2011 - 04:42 PM

Adding a MessageBox or an InputBox requires the use of a Windowing API, which honestly is likely beyond your abilities at this point. For example, this is a Win32 API tutorial.
Was This Post Helpful? 1
  • +
  • -

#5 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 617
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Message Box / Input Box ?

Posted 23 March 2011 - 07:19 PM

An output MessageBox is trivial, but an Input box would more often than not require you to design your own dialog box, which requires a reasonable understanding of the Windows API.

Here's something for you to play around with.

#include <Windows.h>

int main()
{
    MessageBox(NULL, L"Hello, world", L"Test", MB_OK | MB_ICONINFORMATION);
    return 0;
}

Was This Post Helpful? 0
  • +
  • -

#6 xkaijinx  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 09-March 11

Re: Message Box / Input Box ?

Posted 25 March 2011 - 05:46 AM

Is that Windows API site for C++ or for C? Alot of the examples seem to be coded in C, not sure how to convert this easily.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1