int Y, X ,I, Z;
Z=1;
X=0;
FOR(I=0, I<=5, I=I+1)
{Y=X*I + I*I;
cout<<Y<<X<<I;
X=X+Z;
}
For partial codeI am having trouble finding what is wrong in this partial code, can an
Page 1 of 1
11 Replies - 407 Views - Last Post: 12 December 2009 - 01:47 AM
#1
For partial code
Posted 12 December 2009 - 12:36 AM
Replies To: For partial code
#2
Re: For partial code
Posted 12 December 2009 - 12:41 AM
Please give us some more details of your problem.
( a ) Does your code compile?
( b ) Any errors or warnings? If there are, then share them with us.
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect? Give details.
#3
Re: For partial code
Posted 12 December 2009 - 12:46 AM
#4
Re: For partial code
Posted 12 December 2009 - 12:50 AM
janotte, on 11 Dec, 2009 - 11:41 PM, said:
Please give us some more details of your problem.
( a ) Does your code compile?
( b ) Any errors or warnings? If there are, then share them with us.
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect? Give details.
Well actually this is part of an assignment where I am just supposed to find a error in this piece of code. It can be logical or syntax. The only thin I can see is that I=I+1 could be replaced by i+1. Other than that, am I missing something? Any advice would be greatly appreciated.
#5
Re: For partial code
Posted 12 December 2009 - 01:07 AM
cpenbutt, on 12 Dec, 2009 - 01:50 AM, said:
i+1 would simply perform i+1. The output would not be assigned back into the variable. i=i+1 would assign the value of the integer i, incremented by one into the variable i.
int main(void) {
int i=0;
printf("%i\n",i+1);
// i still equal zero, but the number one prints
i=i+1;
printf("%i\n",i);
// the number one prints, because it's the value inside of i
return 0;
}
Make sense?
#6
Re: For partial code
Posted 12 December 2009 - 01:14 AM
no2pencil, on 12 Dec, 2009 - 12:07 AM, said:
cpenbutt, on 12 Dec, 2009 - 01:50 AM, said:
i+1 would simply perform i+1. The output would not be assigned back into the variable. i=i+1 would assign the value of the integer i, incremented by one into the variable i.
int main(void) {
int i=0;
printf("%i\n",i+1);
// i still equal zero, but the number one prints
i=i+1;
printf("%i\n",i);
// the number one prints, because it's the value inside of i
return 0;
}
Make sense?
Yes that makes sense. Thank you
#7
Re: For partial code
Posted 12 December 2009 - 01:21 AM
cpenbutt, on 12 Dec, 2009 - 01:50 AM, said:
& again, we need a little bit of detail.
Y=X*I + I*I;
The above looks right to me. But depending on what value you are expected to get form this, there is a little pain in the ass called order of operations.
#8
Re: For partial code
Posted 12 December 2009 - 01:28 AM
#9
Re: For partial code
Posted 12 December 2009 - 01:34 AM
cpenbutt, on 12 Dec, 2009 - 02:28 AM, said:
You truly are preaching to the quire
I wish I could help you more, but I don't see anything wrong with that code, other than the spacing is atrocious & the variables are in caps.
Neither of those would cause an error, but it's read like a train wreck.
#10
Re: For partial code
Posted 12 December 2009 - 01:38 AM
Is there a difference between "," and ";" in C/C++ syntax?
Is that important here?
#11
Re: For partial code
Posted 12 December 2009 - 01:39 AM
#12
Re: For partial code
Posted 12 December 2009 - 01:47 AM
|
|

New Topic/Question
Reply




MultiQuote




|