Connecting Tech Pros Worldwide Help | Site Map

problem with my code.....

ianenis.tiryaki@gmail.com
Guest
 
Posts: n/a
#1: Mar 23 '07
here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?


13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
18 t = a[x];
19 y = x;
20 do {
21 a[y] = a[y - 1];
22 y--;
23 } while (y 0 && a[y - 1] t);
24 a[y] = t;
25 }
26 }
27 return;
28 }
29 int main (int argc, char **argv)
30 {
31 int a[10];
32 char reply;
33 for (int i = 0; i < 10; i++) a[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;

Ian Collins
Guest
 
Posts: n/a
#2: Mar 23 '07

re: problem with my code.....


ianenis.tiryaki@gmail.com wrote:
Quote:
here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?
>
Add a counter.
Quote:
>
13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
18 t = a[x];
19 y = x;
20 do {
21 a[y] = a[y - 1];
22 y--;
23 } while (y 0 && a[y - 1] t);
24 a[y] = t;
25 }
26 }
27 return;
28 }
29 int main (int argc, char **argv)
30 {
31 int a[10];
32 char reply;
33 for (int i = 0; i < 10; i++) a[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;
>

--
Ian Collins.
ianenis.tiryaki@gmail.com
Guest
 
Posts: n/a
#3: Mar 23 '07

re: problem with my code.....


On Mar 22, 4:00 pm, Ian Collins <ian-n...@hotmail.comwrote:
Quote:
ianenis.tiry...@gmail.com wrote:
Quote:
here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?
>
Add a counter.
>
Quote:
13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
18 t = a[x];
19 y = x;
20 do {
21 a[y] = a[y - 1];
22 y--;
23 } while (y 0 && a[y - 1] t);
24 a[y] = t;
25 }
26 }
27 return;
28 }
29 int main (int argc, char **argv)
30 {
31 int a[10];
32 char reply;
33 for (int i = 0; i < 10; i++) a[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;
>
--
Ian Collins.- Hide quoted text -
>
- Show quoted text -
i didnt understand what does that mean Ian Collins? please it is
urgent i need to ork on this assignment and turn it in... help me!!!!

Ian Collins
Guest
 
Posts: n/a
#4: Mar 23 '07

re: problem with my code.....


ianenis.tiryaki@gmail.com wrote:
Quote:
On Mar 22, 4:00 pm, Ian Collins <ian-n...@hotmail.comwrote:
>
Quote:
>>ianenis.tiry...@gmail.com wrote:
>>
Quote:
>>>here is my code written below but i could figure out howmany times the
>>>assignment statement at Line 21 execute when my code run?
>>
>>Add a counter.
>>
*Please* don't quote signatures.
Quote:
>
>
i didnt understand what does that mean Ian Collins? please it is
urgent i need to ork on this assignment and turn it in... help me!!!!
>
A variable to count the number of times the line is executed.

Don't leave your homework to the last moment!

--
Ian Collins.
devoreband@gmail.com
Guest
 
Posts: n/a
#5: Mar 23 '07

re: problem with my code.....


i am still confused....????

Ian Collins
Guest
 
Posts: n/a
#6: Mar 23 '07

re: problem with my code.....


devoreband@gmail.com wrote:
Quote:
i am still confused....????
>
About what?

--
Ian Collins.
devoreband@gmail.com
Guest
 
Posts: n/a
#7: Mar 23 '07

re: problem with my code.....


so this guy supposed to add a variable to be able to count stuff or
what...?? i am trying to learn C++ too and this is kind of interesting
if anyone can answer my question i would appreciate..

Ian Collins
Guest
 
Posts: n/a
#8: Mar 23 '07

re: problem with my code.....


devoreband@gmail.com wrote:
Quote:
so this guy supposed to add a variable to be able to count stuff or
what...?? i am trying to learn C++ too and this is kind of interesting
if anyone can answer my question i would appreciate..
>
What question?

Please quote some context, this post does not make any sense on its own.

--
Ian Collins.
devoreband@gmail.com
Guest
 
Posts: n/a
#9: Mar 23 '07

re: problem with my code.....



as far as i understand his question, they ask him to find a way to
figure out how many times one line executes when you run the code.
What i am saying is is there any predefined function or something like
that you can use to figure it out or what else you can do?

Ian Collins
Guest
 
Posts: n/a
#10: Mar 23 '07

re: problem with my code.....


devoreband@gmail.com wrote:
Quote:
as far as i understand his question, they ask him to find a way to
figure out how many times one line executes when you run the code.
What i am saying is is there any predefined function or something like
that you can use to figure it out or what else you can do?
>
No.

That's why I suggested adding a counter variable to the code that can be
incremented on each assignment. Computers are better at counting than
people.

--
Ian Collins.
Sarath
Guest
 
Posts: n/a
#11: Mar 23 '07

re: problem with my code.....


On Mar 23, 7:58 am, ianenis.tiry...@gmail.com wrote:
Quote:
here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?
>
13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
Seems this condition will execute always. Did you intend
comparison("==") instead of assigment("=")?

Regards,
Sarath
http://sarathc.wordpress.com/

Jim Langston
Guest
 
Posts: n/a
#12: Mar 23 '07

re: problem with my code.....


<devoreband@gmail.comwrote in message
news:1174606785.152665.180900@p15g2000hsd.googlegr oups.com...
Quote:
>
as far as i understand his question, they ask him to find a way to
figure out how many times one line executes when you run the code.
What i am saying is is there any predefined function or something like
that you can use to figure it out or what else you can do?
The orignal question was obvoiusly homework and it is the custom of this
group to only give points to homework, not do their assignments for them.
Also, you should always quote from the message you are replying to, as I
have here.

A counter is just a variable that gets incremented.

int a = 0;

do (whilesomethingistrue)
{
++a;
// do some stuff
};

std::cout << "Number of times exectued: " << a << "\n':

Understand?


Bo Persson
Guest
 
Posts: n/a
#13: Mar 24 '07

re: problem with my code.....


Sarath wrote:
:: On Mar 23, 7:58 am, ianenis.tiry...@gmail.com wrote:
::: here is my code written below but i could figure out howmany times
::: the assignment statement at Line 21 execute when my code run?
:::
::: 13 void f1(int a[]) {
::: 14 int x, y;
::: 15 int t;
::: 16 for(x = 1; x < 10; x++) {
::: 17 if(a[x] = a[x - 1]) {
::
:: Seems this condition will execute always. Did you intend
:: comparison("==") instead of assigment("=")?
::

Possibly. But it will not execute if the assigned value is zero (and thus
convertible to false).

I thought that was part of the original difficulties - the execution is
controlled by the actual data. .-)



Bo Persson


Closed Thread