# lost! need some help!

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 02-15-2009
hockey1
lost! need some help!
hi guys i know this forum isnt for homework but im taking a software design class and wasnt able to make class on friday so im pretty lost on this assignment. i tried the book and managed to come up with this but its not working at all. the program is supposed to calculate the values of the equation with the givin values of a, b, and c taken from the arrays and use a for loop and output them as follows:

set 1: a=1, b=2, c=3
result=58
set 2: a=4, b=5, c=6
result=59
.
.
.
.
.

here's what ive come up with so far:
insert
Code:

```#include <stdio.h> #define CONTSANT 5.9 main() {         int a[7] = { 5.6, 7.3, 6, 12.2, 2, 3.2 }         int b[7] = { 0.5, 3, 8, 10.3, 4.1, 4,3 }         int c[7] = { 1, 3.3, 6.5, 6.6, 8.4, 15.3 }         int countera;         int counterb;         int counterc;         for ( countera = 1; i <= 6; ++i )                 aoutvalues[countera] = CONSTANT*a-2/(b+c)-3*c^2;         for (countera = 0; i <= 6; ++i )                 printf ("a = %i, b = %i, c = %i\n", a, b, c, aoutvalues);         for ( counterb = 1; i <= 6; ++i )                 boutvalues[counterb] = CONSTANT*a-2/(b+c)-3*c^2;         for (counterb = 0; i <= 6; ++i )                 printf ("a = %i, b = %i, c = %i\n", a, b, c, boutvalues);         for ( counterc = 1; i <= 6; ++i )                 coutvalues[counterc] = CONSTANT*a-2/(b+c)-3*c^2;         for (counterc = 0; i <= 6; ++i )                 printf ("a = %i, b = %i, c = %i\n", a, b, c, coutvalues); }```
- any help would be much appreciated. again, i only came to this as a last resort.

thanks so much!
• 02-15-2009

• 02-15-2009
MK27
Not on gcc it won't, and there's some obvious reasons.

Why don't you at least try and compile it once yourself before you post? You have gotten well beyond the point where that should have happened already.

Viewed as pseudo-code, I would say you can turn those 6 seperate loops into 2 nested ones.
• 02-15-2009
hockey1
no it won't compile.
parse error before '{' oken
parse error before "int"
parse error before "for"
• 02-15-2009
hockey1
ok i found the obvious semi colons missing and put them in so the code looks like this now. still wont compile though...

insert
Code:

```#include <stdio.h> #define CONTSANT 5.9 {         int a[7] = { 5.6, 7.3, 6, 12.2, 2, 3.2 };         int b[7] = { 0.5, 3, 8, 10.3, 4.1, 4,3 };         int c[7] = { 1, 3.3, 6.5, 6.6, 8.4, 15.3 };         int countera;         int counterb;         int counterc;         for ( countera = 1; i <= 6; ++i )                 aoutvalues[countera] = CONSTANT*a-2/(b+c)-3*c^2;         for (countera = 0; i <= 6; ++i )                 printf ("a = %i, b = %i, c = %i\n", a, b, c, aoutvalues);         for ( counterb = 1; i <= 6; ++i )                 boutvalues[counterb] = CONSTANT*a-2/(b+c)-3*c^2;         for (counterb = 0; i <= 6; ++i )                 printf ("a = %i, b = %i, c = %i\n", a, b, c, boutvalues);         for ( counterc = 1; i <= 6; ++i )                 coutvalues[counterc] = CONSTANT*a-2/(b+c)-3*c^2;         for (counterc = 0; i <= 6; ++i )                 printf ("a = %i, b = %i, c = %i\n", a, b, c, coutvalues); }```
and if i turn all those for loops into just a couple how would i go about doing that?
• 02-15-2009
MK27
Quote:

Originally Posted by hockey1
no it won't compile.
parse error before '{' oken
parse error before "int"
parse error before "for"

That's because you forgot some ; after some } on lines 5-7. After that, you will find out what further problems exist ;)

That's why you should have started by testing your method on just one set before you proceeded to write more code. You can even do this:
Code:

```int main() {         int a[7] = { 5.6, 7.3, 6, 12.2, 2, 3.2 };         return 0; }```
Which will compile without an error, whereas this does not:
Code:

```int main() {         int a[7] = { 5.6, 7.3, 6, 12.2, 2, 3.2 }         return 0; }```
While this program doesn't do anything (and confuses floating point numbers with integers), you at least know it will create an executable you can run. So every time you add a line or so, try compiling so you don't end up wasting time applying erroneous methods.

Sorry, our posts crossed. You next problem is a missing "i".
• 02-15-2009
Hockey1, you have a wrong idea about this forum. We help students with homework all the time!

What we don't do, is code up programs for students that won't work at the programming assignment, and just post up their assignment, along with a big "help me!". :(

And welcome to the C forum!

Please add the int main(void) function to the program, Hockey1! Every C program must have a main() function. For technical reasons, int main(void), is the way to go. Note that you'll need to have a "return 0" at the end of that main() function. That just means that your program terminated normally.
• 02-15-2009
MK27
Quote:

What we don't do, is code up programs for students that won't work at the programming assignment, and just post up their assignment,

I actually tried. However, when I got to this point:
Code:

```#include <stdio.h> #define CONSTANT 5.9 int main () {         float a[7] = { 5.6, 7.3, 6, 12.2, 2, 3.2 };         int i;         for ( i = 1; i <= 6; ++i ) {                 aoutvalues[countera] = CONSTANT*a-2/(b+c)-3*c^2;         }         return 0; }```
I realized I don't know what a, b, and c are, or what aoutvalues was supposed to be.
• 02-15-2009
I've done that myself, more than once, MK.

Some assignments or programming idea's are just *interesting*, and then I want to do them. :p

The last one for me was the password generator. I had written up little permutation listing programs, but never a permutation generator that included all the subsets of those permutations, (the shorter length parts).

So I had fun with that, and of course, the original poster, never bothered to follow up on his request for help. I believe there is an inverse relationship at work - the more interesting the assignment/idea, the more unlikely the OP will ever return so we can enjoy it! ;)

Se la vi!
• 02-15-2009
hockey1
ok guys i refined it even more after searching the book and heres what i got it down to....

insert
Code:

```#include <stdio.h> #define CONSTANT 5.9 int main () {         float a[7] = { 5.6, 7.3, 6, 12.2, 2, 3.2 };         float b[7] = { 0.5, 3, 8, 10.3, 4.1, 4.3 };         float c[7] = { 1, 3.3, 6.5, 6.6, 8.4, 15.3 };         int i;         for ( i = 1; i < 7; ++i ){                 result = CONSTANT*a[i]-2/(b[i]+c[i])-3*c[i]^2;         }         for ( i = 1; i < 7; ++i ){                 printf ("a=%f, b=%f, c=%f\n, result=%f\n", a, b, c, result);         }         return 0; }```
and i'm not trying to get someone to write me the code, just direct me in the right direction as well as maybe a few hints :).

mk27, the a,b, and c values are the ones defined in the arrays at the top. each value for a, b and c are to be plugged into the equation and then i must print the results of the equation in 6 sets corresponding to the values.

the output should look as follows:
set1: a = 5.6, b = 0.5, c = 1
result = (whatever the result of the equation is)

***this one wont compile its giving me the following errors:

error: stray '\127' in program (whats that mean???)
error: syntax error at '#' token (arent my preprocessor directives correct?)
error: parse error before '<' token (in the for loop? isnt this correct?)
error: parse error before "for" (again, i thought it looks right)

thanks again guys.
• 02-15-2009
MK27
In fact ^ is a bit manipulation operator in C.

To do exponents you need to use math.h and pow(), or in this case powf().

You also have some cheese in the first byte of your posted code, if the cheese is real, it could explain
Quote:

error: stray '\127' in program (whats that mean???)
error: syntax error at '#' token (arent my preprocessor directives correct?)
• 02-15-2009
rags_to_riches
You can see the extra character at the start of your code block in the post, the first character.

Also,
Code:

`result = CONSTANT*a[i]-2/(b[i]+c[i])-3*c[i]^2;`
Your last operator here does not do what you're expecting. Assuming you want a power, you want this.
• 02-15-2009
hockey1
i edited what you guys said and came up with this

Code:

```#include <stdio.h> #include <math.h> #define CONSTANT 5.9 int main () {         float a[7] = { 5.6, 7.3, 6, 12.2, 2, 3.2 };         float b[7] = { 0.5, 3, 8, 10.3, 4.1, 4.3 };         float c[7] = { 1, 3.3, 6.5, 6.6, 8.4, 15.3 };         int i;         for ( i = 1; i <= 6; ++i ){                 result = CONSTANT*a[i]-2/(b[i]+c[i])-3*pow (c[i],2);         }         for ( i = 1; i <= 6; ++i ){                 printf ("a=%f, b=%f, c=%f\n, result=%f\n", a, b, c, result);         }         return 0; }```
however, the same 127 error occured and a huge mess of others came up after changing the code dealing with files? maybe the include <math.h>?

is the rest of the code correct?
• 02-15-2009
MK27
Quote:

however, the same 127 error occured and a huge mess of others came up after changing the code dealing with files? maybe the include <math.h>?
Now that is bizarre, isn't it? It might have to do with whatever outlandish thing you are using to create this. Seriously it is very weird and probably nothing to do with C.

Quote:

is the rest of the code correct?
There may be some bad news, hockey1. As soon as you get those alien figures out, the compiler will send you a clue.
• 02-15-2009
hockey1
its coming up with _flock_t errors and parse errors before '*' token??

im so confused now, its only when i have the #include <math.h> after i take that out it compiles with out the crazy mess of errors.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last