SRL Archive - C/C++ Help and Tutorials

Omg it closes.. WHY


Rs-Gp-4U

2008-02-18 10:27:47

Hey guys i know this thread is alot similar to my last thread but i made another cin and it still closes.. ill explain more after this code..

#include<iostream.h>
int main()
{
int myAge;
int yourAge;
int abc;

myAge = 14;

cout << "Hey im " << myAge " years old, how old are you?";
cin >> yourAge;

if (myAge > yourAge)
cout << "Yey im older than you!";

if (myAge < yourAge)
cout << "Ohh man im younger than you!";

if (myAge == yourAge)
cout << "Were the same age!";

cin >> abc;
}

In my last thread Wizzup? told me to put cin >> abc; in && i've did that but what happens is when i click run on Dev-C++ the exe program comes up "Bla bla whats ur age?" Then i type a random age && it closes.. Pls help

Dan Cardin

2008-02-18 11:07:46

at the end put
system("PAUSE");


EDIT: which i think means u can get rid of the "cin >> abc" because you're not using it for anything

Rs-Gp-4U

2008-02-18 13:09:01

Thanks.. it looks as if you've got a brain as well as a rabbit in that hat (y) :) only kidding thank you loads

EDIT: "press any key to continue" comes up after && i've tried \n && everything but it don't work?

Wizzup?

2008-02-18 14:37:23

From: Dan Cardin
at the end put


EDIT: which i think means u can get rid of the "cin >> abc" because you're not using it for anything


cin >> somevar is also often used to 'pauze' your program, I often use it at the end of a c++ program just to see what my program wrote.
Never knew about the pause, nice.

Rs-Gp-4U

2008-02-22 08:07:44

Please reply asap.. right i made yet another program and but the system pause in but it still closes.. heres the code..

#include <iostream.h>

int main()
{
enum Days { Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };

Days DayOff;
int x;

cout << "What day would you like off? (1 - 7) : ";
cin >> x;
DayOff = Days(x);

if (DayOff == Saturday || DayOff == Sunday)
cout << "Your already off on weekends..\n";
else
cout << "Have a nice holday! Your allowed off";

system("PAUSE");

return 0;
}

It still closes.. PLEASE HELP

Dan Cardin

2008-02-22 08:46:08

i was trying to help but i cant get it to compile :(

i had to change #include <iostream.h> to #include <iostream>
then add using namespace std;

then i got some
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
fatal error LNK1120: 1 unresolved externals
error :(:(
but maybe taking out the return(because u dont need it) or putting the return before the system("PAUSE");

Rs-Gp-4U

2008-02-22 08:59:37

Hmm it compiles for me.. Im using Dev-C++.. ive tried getting rid of return etc.. nd swapping them around but no :(

GoF

2008-02-22 13:38:20

Hm. Not sure but would getchar(); work instead of system("pause");.. I have a image it was a way to sort of pause your program :)

serraog

2008-02-22 15:10:37

Instead of a system("pause") command, you could use a wait function and read from the keyboard buffer until a key is pressed (ex. Enter key).

Example function you could add:

void pause()
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max()); //
Clear whatever's still in the buffer
std::cout << "Press Enter to continue . . .\n";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
}

Note: you may not need to use "std::" in front of cin commands if you are using "using namespace std" but just play around with it. This might not be exactly how you want your program to run, but it would be fairly simple to do and effective.

Good luck!

SG

Bobarkinator

2008-02-23 12:38:02

Many people use cin.get(); to stop programs from closing.. I use system("PAUSE");

Rs-Gp-4U

2008-02-24 10:25:35

Bob, even with system pause my program still closes?

solarwind

2008-02-24 20:25:26

From: Rs-Gp-4U
Bob, even with system pause my program still closes?


Oh my non-existant god. I almost cried after seeing this thread. Here's the working code. Enjoy…

Note: this is a better way of doing it, the std::vector way instead of all that enumerator crap.

#include <cstdlib>
#include <iostream>
#include <vector>

std::vector<std::string> days;
int x = 0;


int main(int argc, char *argv[]) {
days.push_back("Monday");
days.push_back("Tuesday");
days.push_back("Wednesday");
days.push_back("Thursday");
days.push_back("Friday");
days.push_back("Saturday");
days.push_back("Sunday");

std::cout << "What day would you like off? (1 - 7): ";
std::cin >> x;

if(x == 6 || x == 7)
std::cout << "Your already off on weekends." << std::endl;
else
std::cout << "Have a nice holday! Your allowed off on " << days[x - 1] << std::endl;

system("PAUSE");

return EXIT_SUCCESS;
}

solarwind

2008-02-24 20:32:38

Alright alright, since you really want the enumeration type thing, here you go… Works, tested, 100% guaranteed, or your money back. Oh wait…

#include <cstdlib>
#include <iostream>
#include <vector>

enum days {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};
int x = 0;


int main(int argc, char *argv[]) {
days dayoff;


std::cout << "What day would you like off? (1 - 7): ";
std::cin >> x;

dayoff = days(x - 1);

if(dayoff == Saturday || dayoff == Sunday)
std::cout << "Your already off on weekends." << std::endl;
else
std::cout << "Have a nice holday! Your allowed off!" << std::endl;

system("PAUSE");

return EXIT_SUCCESS;
}

Korbman

2008-02-25 11:45:22

Ya know…you really don't need 'std::cout' and 'std::cin'….all you need to do is type 'using namespace std' after the #include <iostream>. It's a lot easier, and definitely not as messy.

exppo

2008-02-25 11:48:12


but maybe taking out the return(because u dont need it) or putting the return before the system("PAUSE");



What worked for me :)

solarwind

2008-02-25 16:06:31

From: Korbman
Ya know…you really don't need 'std::cout' and 'std::cin'….all you need to do is type 'using namespace std' after the #include <iostream>. It's a lot easier, and definitely not as messy.


Oh, I'm so stupid I would never have figured that out on my own. Thanks so much for the wonderful tip. I'll be sure to repay you for the goodness you have done for me.

Sarcasm aside, don't talk out of your ass plawks. Namespaces are good and all for certain situations, but it's best to avoid them whenever possible.

Dan Cardin

2008-02-25 18:11:08

i wouldnt say avoid them whenever possible more, know when to not use them, because they do save a lot of time

Korbman

2008-02-27 14:09:59

Relax solarwind, no need for sarcasm. And I am not speaking out of my ass. I fully agree with Dan…when you deal with a simple program that only uses the std:: then a namespace would be perfect (i.e. this program can use a namespace). It would make things much easier. The 'using namespace std' is pretty standard to start off with in programming…but later on, creating different namespaces for classes, objects, and such, will be much helpful.

nprp

2008-02-27 15:04:18

Ok guys my scar 3.14 was running great with the forefeatehrs script….for 6 days straight…it ran for 20hours a day…
now my scar thing closes, after like not even 1hour….what happened…and what should i do now…help will be appreciated……
Please pm me or posting it here is fine as welli guess….but i need some seriuos…help…not only me but around 50 people….have this problem now….

solarwind

2008-02-27 15:46:43

From: Korbman
Relax solarwind, no need for sarcasm. And I am not speaking out of my ass. I fully agree with Dan…when you deal with a simple program that only uses the std:: then a namespace would be perfect (i.e. this program can use a namespace). It would make things much easier. The 'using namespace std' is pretty standard to start off with in programming…but later on, creating different namespaces for classes, objects, and such, will be much helpful.


You'll see what I mean when you actually understand C++ ;)

solarwind

2008-02-27 15:48:08

From: nprp
Ok guys my scar 3.14 was running great with the forefeatehrs script….for 6 days straight…it ran for 20hours a day…
now my scar thing closes, after like not even 1hour….what happened…and what should i do now…help will be appreciated……
Please pm me or posting it here is fine as welli guess….but i need some seriuos…help…not only me but around 50 people….have this problem now….


Umm, gtfo plawks? Sorry to be rude, but it's also rude to post spam in a thread which is dealing with a totally different problem. So… gtfo plawks?

nprp

2008-02-27 15:50:10

So what do u want me to do rite now, like i wanna get the problem solved man…….please can u help me out in some way…..I mean it was working fine before, now it's happening…..i'm using forefeathers script by the way..

Please man if possible a person that knows how to solve this problem for aorund like 50 people…can you please do like a 5minute video maybe? please?

solarwind

2008-02-27 15:54:48

From: nprp
So what do u want me to do rite now, like i wanna get the problem solved man…….please can u help me out in some way…..I mean it was working fine before, now it's happening…..i'm using forefeathers script by the way..

Please man if possible a person that knows how to solve this problem for aorund like 50 people…can you please do like a 5minute video maybe? please?


Lol, someone ban this kid…

[S]paz

2008-02-27 15:58:15

thats called thread hi-jacking…. make your own thread and ask again

~Spaz

Korbman

2008-02-27 16:58:48

From: solarwind
You'll see what I mean when you actually understand C++ ;)

And what the fuck is that supposed to mean? Are you assuming that because I showed you that you were using far too complex coding methods for such a simple program I don't actually understand C++? I sense a tad bit of arrogance in you attitude solarwind…and I feel that it is getting the best of you. There is no need to try and "show off" what you know. The program you helped Rs-Gp-4U with could have been simplified. The program he was trying to write was just basic coding. You used things that aren't needed for a beginner.

You did not need to use an enum function, a basic array would have sufficed (no more need for #include <vector>)…the 'int argc, char *argv[]' inside the int main() is not needed…you wouldn't need to set 'daysoff' if there is no enum function 'days'…we've already gone over the fact that you really don't need the 'std::' as long as 'using namespace std;' is set at beginning of the program…return EXIT_SUCCESS is not needed either, that can be changed to return 0…and the #include <cstdlib> is not needed either.

See look at that…I made it easier for a beginner to understand by using basic concepts. Quick and simple.

You made this simple program far FAR too complicated. It was as if you were trying to show off what you know to a beginner. That's pretty pathetic dude. I'm glad you know a good deal of programming, but grow up a little and get over yourself. Look at me as your equal…I do understand C++ as you do.

Pull your head out of your ass and stop being an arrogant fag ;)

solarwind

2008-02-27 17:48:26

From: Korbman
And what the fuck is that supposed to mean? Are you assuming that because I showed you that you were using far too complex coding methods for such a simple program I don't actually understand C++? I sense a tad bit of arrogance in you attitude solarwind…and I feel that it is getting the best of you. There is no need to try and "show off" what you know. The program you helped Rs-Gp-4U with could have been simplified. The program he was trying to write was just basic coding. You used things that aren't needed for a beginner.

You did not need to use an enum function, a basic array would have sufficed (no more need for #include <vector>)…the 'int argc, char *argv[]' inside the int main() is not needed…you wouldn't need to set 'daysoff' if there is no enum function 'days'…we've already gone over the fact that you really don't need the 'std::' as long as 'using namespace std;' is set at beginning of the program…return EXIT_SUCCESS is not needed either, that can be changed to return 0…and the #include <cstdlib> is not needed either.

See look at that…I made it easier for a beginner to understand by using basic concepts. Quick and simple.

You made this simple program far FAR too complicated. It was as if you were trying to show off what you know to a beginner. That's pretty pathetic dude. I'm glad you know a good deal of programming, but grow up a little and get over yourself. Look at me as your equal…I do understand C++ as you do.

Pull your head out of your ass and stop being an arrogant fag ;)


As I remember a famous quote…
"Who's the fool, the fool or the fool who follows the fool?"

As I remember another thing….
Swearing isn't allowed on SRL.

And another thing…
Who's the arrogant one? Me or you who assumes that I am homosexual? You know nothing about me so it is, in fact, you who is the arrogant one ;)

And yet another thing…
I'm pathetic? Who's getting angry over the internets and flaming? ;)

Hehe…

Korbman

2008-02-27 18:03:16

From: solarwind
As I remember a famous quote…
"Who's the fool, the fool or the fool who follows the fool?"

As I remember another thing….
Swearing isn't allowed on SRL.

And another thing…
Who's the arrogant one? Me or you who assumes that I am homosexual? You know nothing about me so it is, in fact, you who is the arrogant one ;)

And yet another thing…
I'm pathetic? Who's getting angry over the internets and flaming? ;)

Hehe…


- The fool is the fool who follows the fool, not the fool who leads the fool. The leader may make mistakes, but it takes a fool to follow the leader and make the same mistake.

- I realized that swearing was not allowed after my final submission. Sorry 'bout that

- Please, give me your definition of arrogant. Now look it up in the dictionary. You'll find that you used it improperly when trying to insult me. ;)

- Yes, I feel that you are pathetic. Then again, I feel that anyone who is arrogant to those around them is pathetic. And, yes, I am getting angry over the internet at you…but that is only because you seem to shut out all help and think you are superior to those around you (i.e. your arrogance). I'm sorry, but arrogance is something I can't stand. Sorry, I'm trying not to consider this flaming…rather, I'd consider it an attempt at a helpful realization on your part.

And life goes on…

solarwind

2008-02-27 18:14:09

From: Korbman
- The fool is the fool who follows the fool, not the fool who leads the fool. The leader may make mistakes, but it takes a fool to follow the leader and make the same mistake.

- I realized that swearing was not allowed after my final submission. Sorry 'bout that

- Please, give me your definition of arrogant. Now look it up in the dictionary. You'll find that you used it improperly when trying to insult me. ;)

- Yes, I feel that you are pathetic. Then again, I feel that anyone who is arrogant to those around them is pathetic. And, yes, I am getting angry over the internet at you…but that is only because you seem to shut out all help and think you are superior to those around you (i.e. your arrogance). I'm sorry, but arrogance is something I can't stand. Sorry, I'm trying not to consider this flaming…rather, I'd consider it an attempt at a helpful realization on your part.

And life goes on…


Merry christmas, and a happy New Year! By the way, I don't think I'm superior to anyone. You don't know me… Obviously…

Korbman

2008-02-27 18:39:35

From: solarwind
Merry christmas, and a happy New Year! By the way, I don't think I'm superior to anyone. You don't know me… Obviously…


ummm…ok? You are correct in stating that I do not know you. But I do read what you write on the forums, which can give me (or anyone really) a sense of who you are judging by how you write and what you write about. That is why I called you arrogant in the first place.

Anyway…enough of this. This is a pointless conversation that is now turning into worthless posts in this thread. We're supposed to be discussing C++…Let's move on :p

solarwind

2008-02-27 18:52:24

From: Korbman
ummm…ok? You are correct in stating that I do not know you. But I do read what you write on the forums, which can give me (or anyone really) a sense of who you are judging by how you write and what you write about. That is why I called you arrogant in the first place.

Anyway…enough of this. This is a pointless conversation that is now turning into worthless posts in this thread. We're supposed to be discussing C++…Let's move on :p


Bingo!