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 


My first c++ program :>
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Sat Sep 11, 2010 9:41 am    Post subject: My first c++ program :> Reply with quote

This is my first awesome program in c++ Smile

All it really does is neasting a loop inside a loop to print the multiplication table.

Code:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    for(int i=0;i<=12;i++)
    {
       cout<<i<<"\n";
           
       for(int ii=0;ii<=12;ii++)
       {
          cout<<i<<"*"<<ii<<"="<<i*ii<<"\n";     
       }
    }
   
    system("PAUSE");
    return 0;
}

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sat Sep 11, 2010 11:08 am    Post subject: Reply with quote

First of all: System() things are bad, you could better use, getchar or things like that.

Secondly, nice, but what can we do with it?
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Sat Sep 11, 2010 12:18 pm    Post subject: Reply with quote

NoMercy wrote:
First of all: System() things are bad, you could better use, getchar or things like that.

Secondly, nice, but what can we do with it?


You can use it to print a multiplication table mr obvious.

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sat Sep 11, 2010 12:47 pm    Post subject: Reply with quote

NINTENDO wrote:
NoMercy wrote:
First of all: System() things are bad, you could better use, getchar or things like that.

Secondly, nice, but what can we do with it?


You can use it to print a multiplication table mr obvious.


It was not to be mean, it was just a question, since i think everyone at this forum can make that up....

Also, this is not the binary section, this is for questions and such....

mr
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sat Sep 11, 2010 12:48 pm    Post subject: Reply with quote

I would do:

Code:
#include <istream>

int main(int argc, char *argv[])
{
    for(int i=0; i<=12; i++)
    {
       printf("%d\n", i);
           
       for(int ii=0; ii<=12; ii++)
       {
          printf("%d * %d = %d\n", i, ii, (i * ii));     
       }
    }
   
    std::cin.get();
    return 0;
}
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Sat Sep 11, 2010 3:18 pm    Post subject: Reply with quote

CometJack wrote:
I would do:

Code:
#include <istream>

int main(int argc, char *argv[])
{
    for(int i=0; i<=12; i++)
    {
       printf("%d\n", i);
           
       for(int ii=0; ii<=12; ii++)
       {
          printf("%d * %d = %d\n", i, ii, (i * ii));     
       }
    }
   
    std::cin.get();
    return 0;
}


Ye it looks neater and runs faster I think.

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Sat Sep 11, 2010 7:20 pm    Post subject: Reply with quote

Wow. Showing your skills fellas. I'm surprised no one caught it.
Code:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    long close;
    for(int i=0;i<=12;i++)
    {
       cout<<i<<"\n";
           
       for(int ii=0;ii<=12;ii++)
       {
          cout<<i<<"*"<<ii<<"="<<i*ii<<"\n";     
       }
    }
   
    //system("PAUSE");
    cin>>close;
    return 0;
}


printf is not faster than cout in every case, depends on the compiler.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sat Sep 11, 2010 9:01 pm    Post subject: Reply with quote

AhMunRa wrote:
Wow. Showing your skills fellas. I'm surprised no one caught it.
Code:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    long close;
    for(int i=0;i<=12;i++)
    {
       cout<<i<<"\n";
           
       for(int ii=0;ii<=12;ii++)
       {
          cout<<i<<"*"<<ii<<"="<<i*ii<<"\n";     
       }
    }
   
    //system("PAUSE");
    cin>>close;
    return 0;
}


printf is not faster than cout in every case, depends on the compiler.


What didn't I catch?

I've also never seen "cin>>close;"; What does that do?
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Sep 11, 2010 10:31 pm    Post subject: Reply with quote

AhMunRa wrote:
printf is not faster than cout in every case, depends on the compiler.


you have bigger problems at hand than printf or cout if speed is an issue.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Sep 11, 2010 10:31 pm    Post subject: Reply with quote

CometJack wrote:
I've also never seen "cin>>close;"; What does that do?


close was variable, he just uses a dud cin to wait for a keystroke.
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sat Sep 11, 2010 11:11 pm    Post subject: Reply with quote

slovach wrote:
CometJack wrote:
I've also never seen "cin>>close;"; What does that do?


close was variable, he just uses a dud cin to wait for a keystroke.


Oh I didn't see "long close;" xD

Is that more efficient than std::cin.get(); ?
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Sat Sep 11, 2010 11:23 pm    Post subject: Reply with quote

In this case not really. It's the same thing.

If you already found this site disregard, if you haven't then it may be useful to you. This site used to have a lot of good programming challenges, you could write a program submit it to the forum for peer review.

http://www.cplusplus.com/

Very good for beginner.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Sep 11, 2010 11:34 pm    Post subject: Reply with quote

People seem to forget that console programs are meant to be ran from the console... they aren't really supposed to pause when they are done doing useful work.
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Sun Sep 12, 2010 12:08 am    Post subject: Reply with quote

People also seem to forget that most Windows users aren't used to typing out and running console apps anymore and having a screen flash without letting them see input can be infuriating to someone that doesn't know how to run a console app.

The pause is so the user may see their input or the programs output. Unless run from command line, it would be open and gone before you could read the first word.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Sep 12, 2010 12:30 am    Post subject: Reply with quote

AhMunRa wrote:
People also seem to forget that most Windows users aren't used to typing out and running console apps anymore and having a screen flash without letting them see input can be infuriating to someone that doesn't know how to run a console app.

The pause is so the user may see their input or the programs output. Unless run from command line, it would be open and gone before you could read the first word.


If you want the user to interact with the program, you make a GUI. Console programs are for back-end work and/or people who know what they are doing.

Furthermore, the way you suggested for pausing a program is flawed. If the buffer contains input when it reaches the 'cin>>close;', it will simply skip over it and close. If you must pause the program for user input, you should do the following:
Code:
std::cin.sync();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
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 1, 2  Next
Page 1 of 2

 
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