View previous topic :: View next topic |
Author |
Message |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Sat Sep 11, 2010 11:08 am Post subject: |
|
|
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 |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Sat Sep 11, 2010 12:18 pm Post subject: |
|
|
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 |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Sat Sep 11, 2010 12:47 pm Post subject: |
|
|
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 |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Sat Sep 11, 2010 12:48 pm Post subject: |
|
|
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 |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Sat Sep 11, 2010 3:18 pm Post subject: |
|
|
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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Sat Sep 11, 2010 7:20 pm Post subject: |
|
|
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 |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Sat Sep 11, 2010 9:01 pm Post subject: |
|
|
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Sep 11, 2010 10:31 pm Post subject: |
|
|
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Sep 11, 2010 10:31 pm Post subject: |
|
|
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 |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Sat Sep 11, 2010 11:11 pm Post subject: |
|
|
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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Sat Sep 11, 2010 11:23 pm Post subject: |
|
|
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 |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sat Sep 11, 2010 11:34 pm Post subject: |
|
|
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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Sun Sep 12, 2010 12:08 am Post subject: |
|
|
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 |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sun Sep 12, 2010 12:30 am Post subject: |
|
|
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 |
|
 |
|