root(s)

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

I have this code I hope it explains itself. I correctly wrote a root
program for simple radicals such as 2 to the 5th power. But I wanted to
expland on that to include a radicand that is 5 cubed for example, raised to
the 5th power. I received this compiler warning too. Am I correct in my
surmise that there is a loop error somewhere?

r.c: In function `main':
r.c:6: warning: comparison between pointer and integer

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
if (argc < 3 || argv > 4) {
fputs("root usage error\n base power(s)\n", stderr);
exit(EXIT_FAILURE);
}
double base, power, powers;
base = strtod(argv[1], NULL);
power = strtod(argv[2], NULL);
if (argv[4] == NULL) {
printf("%.2f\n", base / power);
exit(0);
if (argv[4] != NULL) {
powers = strtod(argv[4], NULL);
printf("%.2f\n", (base * power) / powers);
exit(0);
}
}
return 0;
}

This is pretty complex for me.

Bill
 
T

Tim Harig

the 5th power. I received this compiler warning too. Am I correct in my
surmise that there is a loop error somewhere?

How can you have a loop error if you have no loop?
r.c: In function `main':
r.c:6: warning: comparison between pointer and integer
int main(int argc, char **argv)
if (argc < 3 || argv > 4) {

argv is a (char**); but here your are comparing it against 4, an integer.
 
B

Bill Cunningham

How can you have a loop error if you have no loop?


argv is a (char**); but here your are comparing it against 4, an integer.

Well it would have to be that simple. That then was a typo on my part.
argv should be argc. If that is the only error I might have been right on
this code.

Bill
 
T

Tim Harig

Well it would have to be that simple. That then was a typo on my part.
argv should be argc. If that is the only error I might have been right on

I assumed so much
argv should be argc. If that is the only error I might have been right on
this code.

Nope. You code still has problems; but, given your history here, I am not
about to make a general analyis of your code. I don't feed potential
trolls. You asked a direct question and you got a direct answer.
 
B

Barry Schwarz

On Wed, 8 Jul 2009 17:44:01 -0400, "Bill Cunningham"

I know I'm going to regret this but -
I have this code I hope it explains itself. I correctly wrote a root

Not bloody likely if this program is in any way based on that program.
program for simple radicals such as 2 to the 5th power. But I wanted to

2 to the 5th power is not a radical. The 5th root of 2 would be as
would the equivalent 2 to the 1/5th power.
expland on that to include a radicand that is 5 cubed for example, raised to

You can't have a radicand without a radical.
the 5th power. I received this compiler warning too. Am I correct in my
surmise that there is a loop error somewhere?

Not even close.
r.c: In function `main':
r.c:6: warning: comparison between pointer and integer

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
if (argc < 3 || argv > 4) {
fputs("root usage error\n base power(s)\n", stderr);
exit(EXIT_FAILURE);
}
double base, power, powers;
base = strtod(argv[1], NULL);
power = strtod(argv[2], NULL);
if (argv[4] == NULL) {

This is undefined behavior when argc is 3. If argc is 4, this
expression always evaluates to 1.
printf("%.2f\n", base / power);
exit(0);
if (argv[4] != NULL) {

This statement can never be reached.
powers = strtod(argv[4], NULL);

If it could be reached, this statement would always invoke undefined
behavior.
 
B

Bill Cunningham

Barry Schwarz said:
On Wed, 8 Jul 2009 17:44:01 -0400, "Bill Cunningham"

I know I'm going to regret this but -

If you think you are going to regret posting don't do it.
Not bloody likely if this program is in any way based on that program.


2 to the 5th power is not a radical. The 5th root of 2 would be as
would the equivalent 2 to the 1/5th power.


You can't have a radicand without a radical.

Maybe I am not making myself spoke before. This is what I mean.

(5^3)^5 Is the only why I know how to type it.

Bill
 
B

Bill Cunningham

Barry Schwarz said:
On Wed, 8 Jul 2009 17:44:01 -0400, "Bill Cunningham"

I know I'm going to regret this but -


Not bloody likely if this program is in any way based on that program.


2 to the 5th power is not a radical. The 5th root of 2 would be as
would the equivalent 2 to the 1/5th power.

I'm meaning roots but said power. I'm used to exponents I apologize.
expland on that to include a radicand that is 5 cubed for example, raised
to

You can't have a radicand without a radical.
the 5th power. I received this compiler warning too. Am I correct in my
surmise that there is a loop error somewhere?

Not even close.
r.c: In function `main':
r.c:6: warning: comparison between pointer and integer

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
if (argc < 3 || argv > 4) {
fputs("root usage error\n base power(s)\n", stderr);
exit(EXIT_FAILURE);
}
double base, power, powers;
base = strtod(argv[1], NULL);
power = strtod(argv[2], NULL);
if (argv[4] == NULL) {

This is undefined behavior when argc is 3. If argc is 4, this
expression always evaluates to 1.
printf("%.2f\n", base / power);
exit(0);
if (argv[4] != NULL) {

This statement can never be reached.
powers = strtod(argv[4], NULL);

If it could be reached, this statement would always invoke undefined
behavior.
printf("%.2f\n", (base * power) / powers);
exit(0);
}
}
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top