473,388 Members | 944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

exit command

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

--
Mustafa Zaza
Mar 5 '08 #1
13 6519
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark McEahern | last post by:
Is there a straightforward way to get the exit code from a windows process? I want to write a script that runs a bunch of .sql files against SQL Server using osql. I want it to stop if there's...
8
by: Mike Maxwell | last post by:
<vent> I see there has been traffic over the years on this gripe, so just let me vent my frustration, and add another reason why 'exit' (or possibly exit() or quit() or halt() or some such) should...
11
by: Peter Steele | last post by:
I have a Windows application written in C# that I want to return a non-zero exit code when it it run. The problem is that as a Windows application, there doesn't seem to be a way to control this....
3
by: Micus | last post by:
Greetings, I need to execute 2 applications from an application or batch file. The first app launched has the user enter a product key and the app's exit code will be 0 (failed) or 1...
2
by: GGerard | last post by:
Hello Is there a way to exit all running procedures with one command? Sometimes a procedure(1) will call another procedure(2) which could call a third procedure(3) and what I would like to...
19
by: ern | last post by:
Right now I'm using exit(0) to terminate my program. My program is a console .exe application. After the "exit(0)" line of code is encountered, the console application waits for an enter press,...
7
by: Benzi Eilon | last post by:
I am executing an Expand command in order to expand a CAB file. This is done by calling CreateProcess with the Expand command and then WaitForSingleObject and checking the process exit code. My C++...
5
by: junw2000 | last post by:
My program is about several thousands lines. It takes arguements from the command line. If no arguement is given, it should simply exist. Below is the architectureof main() : int main(int argc,...
2
by: dstork | last post by:
Anyone know how to rename the "Exit Access" command at the bottom of the Office menu. I'd like to rename it to "Exit" as I had done in previous versions of Access. I know I can disable it with ...
1
by: enrico via DotNetMonster.com | last post by:
i created an exitstrip tool on my system and i want my system to ask the user if he/she really wants to exit the application. but when i add a command on the forms close button my exitstrip tool...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.