What command can I use to make the program quite after a certain
condition?
--
Mustafa Zaza 13 6352
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/
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;
}
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/
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
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
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
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
MZaza wrote:
}
else if (c==3)
std::exit(EXIT_FAILURE);
}
Spurious '}'
}
system("PAUSE");
return EXIT_SUCCESS;
}
--
Ian Collins.
MZaza wrote:
}
else if (c==3)
std::exit(EXIT_FAILURE);
}
The brace above does not belong.
Brian
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
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.
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/
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. 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
|
3 posts
views
Thread by Micus |
last post: by
|
2 posts
views
Thread by GGerard |
last post: by
|
19 posts
views
Thread by ern |
last post: by
|
7 posts
views
Thread by Benzi Eilon |
last post: by
|
5 posts
views
Thread by junw2000 |
last post: by
|
2 posts
views
Thread by dstork |
last post: by
|
1 post
views
Thread by enrico via DotNetMonster.com |
last post: by
| | | | | | | | | | |