468,512 Members | 1,351 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

exit command

What command can I use to make the program quite after a certain
condition?

--
Mustafa Zaza
Mar 5 '08 #1
13 6244
MZaza <mu**********@gmail.comwrites:
What command can I use to make the program quite after a certain
condition?
(ITYM "function", not "command").

Heh, it's in your subject line!

#include <cstdlib>

....
if (nasty_thing_happened)
std::exit(EXIT_FAILURE)
....

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
Mar 6 '08 #2
On Mar 6, 2:02 am, Micah Cowan <mi...@hollister.bcsweb.comwrote:
MZaza <mustafa.z...@gmail.comwrites:
What command can I use to make the program quite after a certain
condition?

(ITYM "function", not "command").

Heh, it's in your subject line!

#include <cstdlib>

...
if (nasty_thing_happened)
std::exit(EXIT_FAILURE)
...

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/
I get an error "111 C:\Dev-Cpp\main.cpp expected constructor,
destructor, or type conversion before '(' token"
Here is the code,
}
else if (c==3)
std::exit(EXIT_FAILURE);
}
}

system("PAUSE");
return EXIT_SUCCESS;
}
Mar 6 '08 #3
MZaza <mu**********@gmail.comwrites:
On Mar 6, 2:02 am, Micah Cowan <mi...@hollister.bcsweb.comwrote:
>MZaza <mustafa.z...@gmail.comwrites:
What command can I use to make the program quite after a certain
condition?

(ITYM "function", not "command").

Heh, it's in your subject line!
<snipped example>
>--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/
(Please snip signatures, unless they're important. Looks like some
line-folding was also done.)
>
I get an error "111 C:\Dev-Cpp\main.cpp expected constructor,
destructor, or type conversion before '(' token"
Here is the code,
}
else if (c==3)
std::exit(EXIT_FAILURE);
}
}

system("PAUSE");
return EXIT_SUCCESS;
}
That's not complete code; so I can't diagnose your issue. I do note
that the bracing and indentation don't seem to match up,
quite. Probably you have an extra closing brace after std::exit()?

In any case, please post a minimal, compilable example that
demonstrates the problem you're seeing.

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
Mar 6 '08 #4
On Mar 6, 2:11 am, Micah Cowan <mi...@hollister.bcsweb.comwrote:
MZaza <mustafa.z...@gmail.comwrites:
On Mar 6, 2:02 am, Micah Cowan <mi...@hollister.bcsweb.comwrote:
MZaza <mustafa.z...@gmail.comwrites:
What command can I use to make the program quite after a certain
condition?
(ITYM "function", not "command").
Heh, it's in your subject line!

<snipped example>
--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/

(Please snip signatures, unless they're important. Looks like some
line-folding was also done.)
I get an error "111 C:\Dev-Cpp\main.cpp expected constructor,
destructor, or type conversion before '(' token"
Here is the code,
}
else if (c==3)
std::exit(EXIT_FAILURE);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}

That's not complete code; so I can't diagnose your issue. I do note
that the bracing and indentation don't seem to match up,
quite. Probably you have an extra closing brace after std::exit()?

In any case, please post a minimal, compilable example that
demonstrates the problem you're seeing.

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/
Sorry Miach, I'm 3 days old programmer :)
Here's the full code,

#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
int c;
float x, y;
double r;
char o;

cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}

while (true)

{
cout <<"-To use the result in other mathmatical operation
press 1" <<endl <<"-To clear and continue using the calculator press
2" <<endl <<"-To exit 3" <<endl;
cin >>c;
if (c==1)
{
cin >>o >>y;
switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}
}
else if (c==2)
{
r==0;
cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}

}
}

system("PAUSE");
return EXIT_SUCCESS;
}

If you have other suggestions about my programming way, I'll really
appreciate it.

--
Mustafa Zaza
Mar 6 '08 #5
On Mar 6, 2:15 am, MZaza <mustafa.z...@gmail.comwrote:
On Mar 6, 2:11 am, Micah Cowan <mi...@hollister.bcsweb.comwrote:
MZaza <mustafa.z...@gmail.comwrites:
On Mar 6, 2:02 am, Micah Cowan <mi...@hollister.bcsweb.comwrote:
>MZaza <mustafa.z...@gmail.comwrites:
What command can I use to make the program quite after a certain
condition?
>(ITYM "function", not "command").
>Heh, it's in your subject line!
<snipped example>
>--
>Micah J. Cowan
>Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/
(Please snip signatures, unless they're important. Looks like some
line-folding was also done.)
I get an error "111 C:\Dev-Cpp\main.cpp expected constructor,
destructor, or type conversion before '(' token"
Here is the code,
}
else if (c==3)
std::exit(EXIT_FAILURE);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
That's not complete code; so I can't diagnose your issue. I do note
that the bracing and indentation don't seem to match up,
quite. Probably you have an extra closing brace after std::exit()?
In any case, please post a minimal, compilable example that
demonstrates the problem you're seeing.
--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/

Sorry Miach, I'm 3 days old programmer :)
Here's the full code,

#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
int c;
float x, y;
double r;
char o;

cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}

while (true)

{
cout <<"-To use the result in other mathmatical operation
press 1" <<endl <<"-To clear and continue using the calculator press
2" <<endl <<"-To exit 3" <<endl;
cin >>c;
if (c==1)
{
cin >>o >>y;
switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}
}
else if (c==2)
{
r==0;
cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}

}
}

system("PAUSE");
return EXIT_SUCCESS;

}

If you have other suggestions about my programming way, I'll really
appreciate it.

--
Mustafa Zaza
Sorry, I forgot to paste the new code which I pasted in the exit
function.
Anyway, I guess you know where I pasted it.

--
Mustafa Zaza
Mar 6 '08 #6
MZaza wrote:

Sorry, I forgot to paste the new code which I pasted in the exit
function.
Anyway, I guess you know where I pasted it.
No, show us the actual code that you tried to compile.


Brian
Mar 6 '08 #7
On Mar 6, 2:21 am, "Default User" <defaultuse...@yahoo.comwrote:
MZaza wrote:
Sorry, I forgot to paste the new code which I pasted in the exit
function.
Anyway, I guess you know where I pasted it.

No, show us the actual code that you tried to compile.

Brian
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
int c;
float x, y;
double r;
char o;

cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}

while (true)

{
cout <<"-To use the result in other mathmatical operation
press 1" <<endl <<"-To clear and continue using the calculator press
2" <<endl <<"-To exit 3" <<endl;
cin >>c;
if (c==1)
{
cin >>o >>y;
switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}
}
else if (c==2)
{
r==0;
cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}

}
else if (c==3)
std::exit(EXIT_FAILURE);
}
}

system("PAUSE");
return EXIT_SUCCESS;
}
--
Mustafa Zaza
Mar 6 '08 #8
MZaza wrote:
}
else if (c==3)
std::exit(EXIT_FAILURE);
}
Spurious '}'
}

system("PAUSE");
return EXIT_SUCCESS;
}

--
Ian Collins.
Mar 6 '08 #9
MZaza wrote:

}
else if (c==3)
std::exit(EXIT_FAILURE);
}
The brace above does not belong.

Brian
Mar 6 '08 #10
On Mar 6, 2:30 am, "Default User" <defaultuse...@yahoo.comwrote:
MZaza wrote:
}
else if (c==3)
std::exit(EXIT_FAILURE);
}

The brace above does not belong.

Brian
It's working now, thanks alot guys.

--
Mustafa Zaza
Mar 6 '08 #11
MZaza wrote:
On Mar 6, 3:15 am, Micah Cowan <mi...@hollister.bcsweb.comwrote:
>>
--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/

Ok Micah and thanks.
*Please* trip your posts and *don't* quote signatures!

--
Ian Collins.
Mar 6 '08 #12
Ian Collins <ia******@hotmail.comwrites:
MZaza wrote:
>On Mar 6, 3:15 am, Micah Cowan <mi...@hollister.bcsweb.comwrote:
>>>
--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/

Ok Micah and thanks.

*Please* trip your posts and *don't* quote signatures!
^ ("trim your posts")

MZaza, you're welcome; however, if you don't learn to follow simple
advice about trimming responses to only what's necessary (which advice
you've now been given at least three times now, four if you count
this), you'll probably end up ostracizing yourself from the people who
are most able to help you.

Everyone's time is a limited resource, and while many are here for the
express purpose of making themselves helpful, most don't want to spend
time trying to teach people who don't listen.

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
Mar 6 '08 #13
In article <8c292222-9c52-47d5-8447-0ef30f6aacbe@
59g2000hsb.googlegroups.com>, mu**********@gmail.com says...

[ ... ]

Okay, my first advice: now that you've gotten exit to work, forget that
you ever even heard of it. In C++, exit is a disaster waiting to happen,
and should be used only in dire emergencies.
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
int c;
float x, y;
double r;
char o;

cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;
The code to print out the result is duplicated for every branch of the
switch statement; given a choice, I'd prefer to only once, in one place.

[ ... ]
switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input" <<endl;
}
Likewise, this switch statement looks essentially identical to the one
above -- I'd try to eliminate that duplication. I won't bother quoting
it here, but you seem to have the same switch statement yet a third time
as well.

[ ... ]
else if (c==3)
std::exit(EXIT_FAILURE);
}
}

system("PAUSE");
return EXIT_SUCCESS;
Since this code is in main(), you don't need (or want) to call exit() --
you want to just return from main() and leave it at that.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Mar 6 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mark McEahern | last post: by
8 posts views Thread by Mike Maxwell | last post: by
11 posts views Thread by Peter Steele | last post: by
19 posts views Thread by ern | last post: by
5 posts views Thread by junw2000 | last post: by
1 post views Thread by enrico via DotNetMonster.com | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.