Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Program exiting automatically
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Frostbyt3
Master Cheater
Reputation: 0

Joined: 07 Jan 2008
Posts: 323
Location: Australia

PostPosted: Fri Oct 24, 2008 11:55 pm    Post subject: Reply with quote

Code:
// my second program in C++
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main ()
{
   //Store input
   string input;   
   //Is the program running
   bool exit = false;

   //Main loop
   while (exit == false)       
{
   cout<<">";
   //Get input and store it in input
   getline (cin, input);
   if (input == "quit")
   {
      exit = true;
   }
}
}


Enjoy.
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Oct 25, 2008 12:19 am    Post subject: Reply with quote

Code:
int main(){
   char input[50];
   do{
      std::cin >> input;
         }while(strcmp(input, "quit") != 0);
   return 0;
}
Back to top
View user's profile Send private message
xV
I post too much
Reputation: 1

Joined: 03 Jan 2008
Posts: 3783
Location: Seattle

PostPosted: Sat Oct 25, 2008 2:13 am    Post subject: Reply with quote

slovach wrote:
Code:
int main(){
   char input[50];
   do{
      std::cin >> input;
         }while(strcmp(input, "quit") != 0);
   return 0;
}


D: I haven't even gotten that far yet. I can barely grasp variables.

_________________
Back to top
View user's profile Send private message MSN Messenger
92Garfield
I'm a spammer
Reputation: 57

Joined: 20 Dec 2007
Posts: 5871
Location: Banana Republic Germany

PostPosted: Sat Oct 25, 2008 2:50 am    Post subject: Reply with quote

xViBeSz wrote:
slovach wrote:
cin.sync
cin.ignore / get.

Code:
#include <iostream>

int main (){
   std::cout << "Hello World!";
   std::cout << "I'm a C++ program";
   std::cin.sync();
   std::cin.ignore();
   return 0;
}


:O What's all that std stuff?

Could I get rid of all that std:: if I used:
Code:
using namespace std;

yes and for the prgramm not to close you could do

Code:
cout<<"Press anything to exit or R to restart."<<endl;
cin>>cont; //must declare cont as a variable that may contain letters
if (cont == "R")
{
system("name of your prgram"); //batch code
}

and you need to have this at top

Code:
#include <cstdlib>


you could also use
Code:
getch()

but it will close on any key then and u need

Code:
#include <conio.h>

_________________


Last edited by 92Garfield on Sat Oct 25, 2008 2:52 am; edited 1 time in total
Back to top
View user's profile Send private message
TehBestNewbZ
Expert Cheater
Reputation: 0

Joined: 28 Jul 2006
Posts: 109

PostPosted: Sat Oct 25, 2008 2:51 am    Post subject: Reply with quote

Dude, learn from a book, not from here.
Back to top
View user's profile Send private message
92Garfield
I'm a spammer
Reputation: 57

Joined: 20 Dec 2007
Posts: 5871
Location: Banana Republic Germany

PostPosted: Sat Oct 25, 2008 2:53 am    Post subject: Reply with quote

TehBestNewbZ wrote:
Dude, learn from a book, not from here.

books aint good, they don't asnwer question and rephrase stuff you don't understand
the best is to ask some questions in forum and use google it answers questions

_________________
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Sat Oct 25, 2008 3:19 am    Post subject: Reply with quote

Quote:
books aint good, they don't asnwer question and rephrase stuff you don't understand
the best is to ask some questions in forum and use google it answers questions


books arent always good, but hes not asking question on-purpose, hes only doing it cos hes not following any tutorials, and no asking here is not a good idea at this early stage, go find some tuts and read them to learn the basics, then when you get better, ask us about things your unsure about, prefereably after a quick google

_________________
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sat Oct 25, 2008 3:39 am    Post subject: Reply with quote

Code:
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
   std::string input; // The input will be stored here.
   do {
      std::cout << "Type exit to exit: ";
      std::getline( std::cin, input ); // Store the input from std::cin to input string
   } while( input != "exit" ); // Compare the input to "exit"

   return EXIT_SUCCESS;
}


If you only want to pause your program at exit, use std::cin.sync() and std::cin.ignore():
Code:
std::cout << "Press enter to exit.";
std::cin.sync();
std::cin.ignore();


I agree that reading books isn't always the best way.. Myself, I haven't read a single book about a programming language :) I'd prefer getting some assignments and then just start doing them and when in trouble, use Google or ask someone. The only good way to learn programming is really doing it, you don't learn how to program if you only read books.

slovach: There's an overflow in your program. So, don't do this like slovach does :P
Back to top
View user's profile Send private message
Stonehenge
Master Cheater
Reputation: 0

Joined: 03 Oct 2008
Posts: 280
Location: Unknown Jumphole

PostPosted: Sat Oct 25, 2008 6:46 am    Post subject: Reply with quote

Here is a program I made to convert warp units into c units (speed of light)

Code:
//
//  Converts Warp speeds into c (light speed)
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <strings.h>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
  double c;
  c = 208.3333;
  double warp;
 
  cout << "Enter the warp speed you would like to convert into c units: ";
  cin >> warp;
  warp = warp * c;
 
  cout << "The c speed conversion of the warp speed you entered is: ";
  cout << warp;
  cout << endl;
 
  system("PAUSE");
  return 0;
}


The "don't quit automatically" is in the

system("PAUSE")
return 0;

_________________
Back to top
View user's profile Send private message
dEEznutz
Grandmaster Cheater
Reputation: 0

Joined: 29 Nov 2007
Posts: 514

PostPosted: Sat Oct 25, 2008 7:48 am    Post subject: Reply with quote

Obidos wrote:
Here is a program I made to convert warp units into c units (speed of light)

Code:
//
//  Converts Warp speeds into c (light speed)
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <strings.h>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
  double c;
  c = 208.3333;
  double warp;
 
  cout << "Enter the warp speed you would like to convert into c units: ";
  cin >> warp;
  warp = warp * c;
 
  cout << "The c speed conversion of the warp speed you entered is: ";
  cout << warp;
  cout << endl;
 
  system("PAUSE");
  return 0;
}


The "don't quit automatically" is in the

system("PAUSE")
return 0;

Don't use system("pause"). cin.get() is better.

_________________
Learning C++
Back to top
View user's profile Send private message
92Garfield
I'm a spammer
Reputation: 57

Joined: 20 Dec 2007
Posts: 5871
Location: Banana Republic Germany

PostPosted: Sat Oct 25, 2008 9:16 am    Post subject: Reply with quote

system is to use batch code right? so it would work only with windows
_________________
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sat Oct 25, 2008 9:33 am    Post subject: Reply with quote

92Garfield wrote:
system is to use batch code right? so it would work only with windows


It works with all OS
Back to top
View user's profile Send private message MSN Messenger
92Garfield
I'm a spammer
Reputation: 57

Joined: 20 Dec 2007
Posts: 5871
Location: Banana Republic Germany

PostPosted: Sat Oct 25, 2008 10:41 am    Post subject: Reply with quote

noz3001 wrote:
92Garfield wrote:
system is to use batch code right? so it would work only with windows


It works with all OS

im gonna try Razz so its not batch code?

_________________
Back to top
View user's profile Send private message
xV
I post too much
Reputation: 1

Joined: 03 Jan 2008
Posts: 3783
Location: Seattle

PostPosted: Sat Oct 25, 2008 11:29 am    Post subject: Reply with quote

Snootae wrote:
Quote:
books aint good, they don't asnwer question and rephrase stuff you don't understand
the best is to ask some questions in forum and use google it answers questions


books arent always good, but hes not asking question on-purpose, hes only doing it cos hes not following any tutorials, and no asking here is not a good idea at this early stage, go find some tuts and read them to learn the basics, then when you get better, ask us about things your unsure about, prefereably after a quick google


Okay, this is the very first thing that I started to read (the first tutorial) and I used their example code and read the descriptions of what the codes do, but the problem was it was exiting so quick I couldn't even read it and the tutorial didn't tell me to add anything to stop that. >.<

And someone told me to use
Code:
cin.sync();
cin.ignore();


And that works really good and it's simple. Thanks.

_________________
Back to top
View user's profile Send private message MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sat Oct 25, 2008 6:47 pm    Post subject: Reply with quote

92Garfield wrote:
system is to use batch code right? so it would work only with windows
::system() should work on every OS, but ::system("pause") is Windows specific:
Code:
RH:(~)(52)% pause
pause: Command not found.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites