GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Apr-2008, 20:36
Daemonblade777 Daemonblade777 is offline
New Member
 
Join Date: Apr 2008
Posts: 1
Daemonblade777 is on a distinguished road

Opens and Closes...


Ok, I'm starting to learn C++ now. But whenever I compile a program, then run it, the program opens up for a second then instantly closes. I have no clue why it does this. I'm using the same code from the C++ Book I'm learning from. (the code is posted below) I've tried 2 different compilers (Visual C++ 2008 and Dev-C++) and it does the same thing.

If someone could help me with this, please do. Oh, and I've tried running the program on Windows XP and Windows Vista and it opens for a second then closes on both...

Code I'm Using:
CPP / C++ / C Code:
// Game Over
// A first C++ program

#include <iostream>

int main()
{
	std::cout << "Game Over" << std::end1;
	return 0;
}


I've also tried this code, but it doesn't work either:
CPP / C++ / C Code:
// Expensive Calculator
// Demonstrates built-in arithmetic operators

#include <iostream>
using namespace std;

int main()
{
	cout << "7 + 3 = " << 7+ 3 << end1;
	cout << "7 - 3 = " << 7 - 3 << end1;
	cout << "7 * 3 = " << 7 * 3 << end1;
	
	cout << "7 / 3 = " << CC 7 / 3 << end1;
	cout << "7.0 / 3.0 " << 7.0 / 3.0 << end1;
	
	cout << "7 % 3 = " << 7 % 3 << end1;
	
	cout << "7 + 3 * 5 = " << 7 + 3 * 5 << end1;
	cout << "(7 + 3) * 5 = " << (7 + 3) * 5 << end1;
	
	return0;
}
Last edited by LuciWiz : 06-Apr-2008 at 12:06. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 02-Apr-2008, 21:16
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,627
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Opens and Closes...


[quote=Daemonblade777]
Code I'm Using:
CPP / C++ / C Code:
// Game Over
//
	std::cout << "Game Over" << std::end1;
	


That's std::endl, not std::end1, right? (A lower-case ell at the end of endl, not a numeral one.)

You could try:
CPP / C++ / C Code:
#include <iostream>

int main()
{

    std::cout << "Game Over" << std::endl;

    std::cout << "Press 'Enter' to continue . . . ";
    std::cin.get();

    return 0;
}

Similarly:

CPP / C++ / C Code:

using namespace std;

int main()
{
    cout << "7 + 3 = " << 7 + 3 << endl;
    cout << "7 - 3 = " << 7 - 3 << endl;
    cout << "7 * 3 = " << 7 * 3 << endl;

    cout << "7 / 3 = " <<  7 / 3 << endl;
    cout << "7.0 / 3.0 = " << 7.0 / 3.0 << endl;

    cout << "7 % 3 = " << 7 % 3 << endl;

    cout << "7 + 3 * 5 = " << 7 + 3 * 5 << endl;
    cout << "(7 + 3) * 5 = " << (7 + 3) * 5 << endl;

    cout << "Press 'Enter' to continue . . .";
    cin.get();

    return 0;
}

Regards,

Dave
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:18.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.