View previous topic :: View next topic |
Author |
Message |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Tue Mar 03, 2009 8:25 pm Post subject: C++ Help |
|
|
Ok I just started learning C++ about 3 days ago so I decided to create a simple program. So I thought I might just make a program that gives you math questions (dumb I know) anyways it works fine so my problem is I want the last line to be able to be read. So for example cout << " You have gotten 4/5 correct good job"; so after return 0; when its compiled and run it closes after that cout line right away so I want it to be able to stop and have users the ability to close the program or restart it so what function would I use?
_________________
Currently learning C++. You can't stop me babe!!! |
|
Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Mar 03, 2009 8:36 pm Post subject: |
|
|
Use the sleep(int) function.
|
|
Back to top |
|
 |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Tue Mar 03, 2009 8:45 pm Post subject: |
|
|
nwongfeiying wrote: | Use the sleep(int) function. |
Um ok how would I fit that into my source? sleep Piss;?
_________________
Currently learning C++. You can't stop me babe!!! |
|
Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Tue Mar 03, 2009 8:57 pm Post subject: |
|
|
nwong was saying use
Which would make it Sleep or pause at that line for 1 second (you can change it)
simplest way is to add
at the end of your code
however, it isnt the most memory efficient.
the best way is to add
Code: | std::cin.sync();
std::cin.ignore(); |
remove the std:: 's if you added Code: | using namespace std; | to your code
_________________
|
|
Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Tue Mar 03, 2009 9:02 pm Post subject: |
|
|
Quote: | Use the sleep(int) function. |
That was a horrible suggestion. He wants to be able to start the proggram again from the beginning without reopening, not pause execution (but you suggestion would still be shit).
It's time for you to learn about loops. There's for, while, and do while loops. While will be the easiest to use although do while would work better.
Basically, everything in the while loop will execute then repeat as long as a conditional (like if statement) is true.
Code: |
int doProgram = 1;
while(doProgram == 1){
all your code;
cout >> "again? 1 - yes, 0 - no";
cin << doProgram;}
return 0; |
When it gets to the loop, it'll check if the statement is true or false. if it's false, it'll skip over it. if true, it'll start the loop. When it gets to the end of the loop, execution will go right back to the start of the loop and check the conditional again.
_________________
|
|
Back to top |
|
 |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Tue Mar 03, 2009 9:24 pm Post subject: |
|
|
HalfPrime wrote: | Quote: | Use the sleep(int) function. |
That was a horrible suggestion. He wants to be able to start the proggram again from the beginning without reopening, not pause execution (but you suggestion would still be shit).
It's time for you to learn about loops. There's for, while, and do while loops. While will be the easiest to use although do while would work better.
Basically, everything in the while loop will execute then repeat as long as a conditional (like if statement) is true.
Code: |
int doProgram = 1;
while(doProgram == 1){
all your code;
cout >> "again? 1 - yes, 0 - no";
cin << doProgram;}
return 0; |
When it gets to the loop, it'll check if the statement is true or false. if it's false, it'll skip over it. if true, it'll start the loop. When it gets to the end of the loop, execution will go right back to the start of the loop and check the conditional again. |
Ok you guys here's the source, at the end of the program I would like to add a line that gives the user a choice to restart or close.
Code: | //attempting to create a program
#include <iostream>
using namespace std;
int main ()
{
int Iss;
cout << "Math Pratice Elite: Made by FirePhoenix\n";
cout << "\nSimply answer a few math questions, to see how good you are at Math!\n";
cout << "\n1. What is 1+1?: ";
cin >> Iss;
if (Iss == 2)
cout << "\nYou are correct!\n";
else
cout << "\nYour wrong.\n";
cout << "\n2. What is 4+4?: ";
cin >> Iss;
if (Iss == 8)
cout << "\nYou are correct!\n";
else
cout << "\nYour wrong!\n";
cout << "\n3. What is 6+6?: ";
cin >> Iss;
if (Iss == 12)
cout << "\nYou are correct!\n";
else
cout << "\nYou are wrong!\n";
cout << "\n4. What is 3+2?: ";
cin >> Iss;
if (Iss = 5)
cout << "\nYou are correct!\n";
else
cout << "\nYou are wrong!\n";
cout << "\n5. What is 4+5?: ";
cin >> Iss;
if (Iss == 9)
cout << "\nYou are correct!";
else
cout << "\n You are wrong!";
return 0;
} |
As you can see I'm only using the if else condition which seems to work fine But I get what your saying HalfPrime.
_________________
Currently learning C++. You can't stop me babe!!!
Last edited by FirePhoenix on Tue Mar 03, 2009 10:11 pm; edited 1 time in total |
|
Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Tue Mar 03, 2009 9:53 pm Post subject: |
|
|
if/if-else statements aren't loops, they're just conditionals. A loop is basically a conditional that repeats as long as it's true.
Code: |
...
int Iss, doProgram;
doProgram = 1;
cout << "Math Pratice Elite: Made by FirePhoenix\n";
cout << "\nSimply answer a few math questions, to see how good you are at Math!\n";
while(doProgram == 1){
cout << "\n1. What is 1+1?: ";
...
if (Iss == 9)
cout << "\nYou are correct!";
else
cout << "\n You are wrong!";
cout >> "again? 1 - yes, 0 - no";
cin << doProgram;}
cout << "bb";
return 0;
} |
Here's a simple example of a loop that'll print the numbers from 1-10
Code: |
int c=1;
while(c<=10){
cout >> c;
c++;}
|
_________________
|
|
Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Mar 03, 2009 10:09 pm Post subject: |
|
|
Halfprime, you evaluate me and so I will evaluate you.
I think your suggestion is shit because you only explain the basics of the loop and neglected to teach him how to create a function and call it.
|
|
Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Tue Mar 03, 2009 10:17 pm Post subject: |
|
|
nwongfeiying wrote: | [you] neglected to teach him how to create a function and call it. |
Why would he need to be calling functions for something that simple?
_________________
|
|
Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Tue Mar 03, 2009 10:19 pm Post subject: |
|
|
Code: |
BOOL NopSleep(int NumofSomekind..)
{
__asm
{
xor eax,eax//zero out eax so eax = 0...
loop:
nop
nop
nop
nop
nop
//enough nops for a whole second (not included)...
inc eax//increment eax so eax = eax + 1(i mean that it increments the number sequentially..)
cmp eax, NumofSomeKind//compare the incremented value to the number inputed..
jl loop//repeat the look if eax less then
}
MessageBoxW(0,L"Hello World",L"Yall can byte me..",0);
return
}
|
|
|
Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Mar 03, 2009 10:46 pm Post subject: |
|
|
manc wrote: | nwongfeiying wrote: | [you] neglected to teach him how to create a function and call it. |
Why would he need to be calling functions for something that simple? |
He'll need to learn it sooner or later.
|
|
Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Tue Mar 03, 2009 10:51 pm Post subject: |
|
|
nwongfeiying wrote: | Halfprime, you evaluate me and so I will evaluate you.
I think your suggestion is shit because you only explain the basics of the loop and neglected to teach him how to create a function and call it.
 |
Good thing I in no way care what you think, then.
As for functions, he will learn them when he gets to them. No point in causing confusion by skipping steps. Btw, yours didn't show him how to create a function, either so I guess by your standards, your post is double shit.
_________________
|
|
Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Mar 03, 2009 10:53 pm Post subject: |
|
|
HalfPrime wrote: | nwongfeiying wrote: | Halfprime, you evaluate me and so I will evaluate you.
I think your suggestion is shit because you only explain the basics of the loop and neglected to teach him how to create a function and call it.
 |
Good thing I in no way care what you think, then.
As for functions, he will learn them when he gets to them. No point in causing confusion by skipping steps. Btw, yours didn't show him how to create a function, either so I guess by your standards, your post is double shit. |
Well, you didn't teach him in the quoted post above. So, your post is triple shit
|
|
Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Tue Mar 03, 2009 11:11 pm Post subject: |
|
|
nwongfeiying wrote: | HalfPrime wrote: | nwongfeiying wrote: | Halfprime, you evaluate me and so I will evaluate you.
I think your suggestion is shit because you only explain the basics of the loop and neglected to teach him how to create a function and call it.
 |
Good thing I in no way care what you think, then.
As for functions, he will learn them when he gets to them. No point in causing confusion by skipping steps. Btw, yours didn't show him how to create a function, either so I guess by your standards, your post is double shit. |
Well, you didn't teach him in the quoted post above. So, your post is triple shit  |
He's obviously following a tutorial already and will get there at his own pace. If he has any problems with it then, he can come and ask for more help. I just hope there's someone other than you here when he does so he can get some real help.
_________________
|
|
Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Wed Mar 04, 2009 5:18 am Post subject: |
|
|
nwongfeiying wrote: | HalfPrime wrote: | nwongfeiying wrote: | Halfprime, you evaluate me and so I will evaluate you.
I think your suggestion is shit because you only explain the basics of the loop and neglected to teach him how to create a function and call it.
 |
Good thing I in no way care what you think, then.
As for functions, he will learn them when he gets to them. No point in causing confusion by skipping steps. Btw, yours didn't show him how to create a function, either so I guess by your standards, your post is double shit. |
Well, you didn't teach him in the quoted post above. So, your post is triple shit  |
Your posts are always shit.
_________________
CLICK TO HAX MAPLESTORAY ^ !!!! |
|
Back to top |
|
 |
|