On Mar 6, 2:02 am, Micah Cowan <mi...@holliste r.bcsweb.comwro te:
MZaza <mustafa.z...@g mail.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_ha ppened)
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);
}
}
On Mar 6, 2:02 am, Micah Cowan <mi...@holliste r.bcsweb.comwro te:
>MZaza <mustafa.z...@g mail.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...
On Mar 6, 2:11 am, Micah Cowan <mi...@holliste r.bcsweb.comwro te:
MZaza <mustafa.z...@g mail.comwrites:
On Mar 6, 2:02 am, Micah Cowan <mi...@holliste r.bcsweb.comwro te:
MZaza <mustafa.z...@g mail.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;
On Mar 6, 2:15 am, MZaza <mustafa.z...@g mail.comwrote:
On Mar 6, 2:11 am, Micah Cowan <mi...@holliste r.bcsweb.comwro te:
>
>
>
MZaza <mustafa.z...@g mail.comwrites:
On Mar 6, 2:02 am, Micah Cowan <mi...@holliste r.bcsweb.comwro te:
>MZaza <mustafa.z...@g mail.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.
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;
>On Mar 6, 3:15 am, Micah Cowan <mi...@holliste r.bcsweb.comwro te:
>>>
>>--
>>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...
In article <8c292222-9c52-47d5-8447-0ef30f6aacbe@
59g2000hsb.goog legroups.com>, mustafa.zaza@gm ail.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.
Comment