NetBeans (exit value 2

W

william redman

I've been running programs on NetBeans for a while and then yesterday I tried to run this program:
#include <stdio.h>

int main(void)
{
int j, number, trianglenumber, counter, n;
printf ("How many loops do you want?");
scanf ("%i ", n);
for (counter = 1; counter<=n; counter++){
printf ("What number do you want?: ");
scanf ("%i ", number);
trianglenumber = 0;
j = 1;
for ( ; j<=number; ++j)
trianglenumber= j + trianglenumber;
printf ("The triangle number of %i is %i", number, trianglenumber);
}
return 0;

}
After I tried to build it displayed BUILD FAILED (exit value 2, total time: 1s). Does anyone know anything about this?
 
J

James Kuyper

I've been running programs on NetBeans for a while and then yesterday I tried to run this program:
#include <stdio.h>

int main(void)
{
int j, number, trianglenumber, counter, n;
printf ("How many loops do you want?");
scanf ("%i ", n);

n is an int, "%i" expects a pointer to int. Because this mis-match
occurs in the variable-arguments portion of the scanf() argument list,
the behavior is undefined, no diagnostic is required, but many modern
compilers will identify such mismatches in string literals used as scanf
or printf format strings.
for (counter = 1; counter<=n; counter++){
printf ("What number do you want?: ");
scanf ("%i ", number);

This has the same issue as the previous case.
trianglenumber = 0;
j = 1;
for ( ; j<=number; ++j)
trianglenumber= j + trianglenumber;
printf ("The triangle number of %i is %i", number, trianglenumber);
}
return 0;

}
After I tried to build it displayed BUILD FAILED (exit value 2, total time: 1s). Does anyone know anything about this?

That's not particularly helpful! If you have any choice in the matter,
find something that gives better warning messages to compile your code.
 
K

Keith Thompson

william redman said:
I've been running programs on NetBeans for a while and then yesterday
I tried to run this program:

#include <stdio.h>

int main(void)
{
int j, number, trianglenumber, counter, n;
printf ("How many loops do you want?");
scanf ("%i ", n);
for (counter = 1; counter<=n; counter++){
printf ("What number do you want?: ");
scanf ("%i ", number);
trianglenumber = 0;
j = 1;
for ( ; j<=number; ++j)
trianglenumber= j + trianglenumber;
printf ("The triangle number of %i is %i", number, trianglenumber);
}
return 0;

}
After I tried to build it displayed BUILD FAILED (exit value 2, total
time: 1s). Does anyone know anything about this?

There are two errors in your code, but none that require a diagnostic or
that I'd expect to cause a compiler to reject it. James Kuyper already
pointed out the errors: you need
scanf("%i", &n);
rather than
scanf("%i, n);

Possibly your compiler is being invoked with an option that turns
warnings into fatal errors (such as "gcc -Werror"), which would explain
why the build fails. But *any* IDE worth what you paid for it (yes,
even if it's free) should show you the actual diagnostic messages
produced by the compiler.

Perhaps the integration between your IDE (NetBeans) and your compiler
(which one are you using?) is not set up properly.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top