473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

problem with my code.....

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;

Mar 22 '07 #1
12 1212
ia*************@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?
Add a counter.
>
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.
Mar 22 '07 #2
On Mar 22, 4:00 pm, Ian Collins <ian-n...@hotmail.comwrote:
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?

Add a counter.
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!!!!

Mar 22 '07 #3
ia*************@gmail.com wrote:
On Mar 22, 4:00 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>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?

Add a counter.
*Please* don't quote signatures.
>

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.
Mar 22 '07 #4
i am still confused....????

Mar 22 '07 #5
de********@gmail.com wrote:
i am still confused....????
About what?

--
Ian Collins.
Mar 22 '07 #6
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..

Mar 22 '07 #7
de********@gmail.com wrote:
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.
Mar 22 '07 #8

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?

Mar 22 '07 #9
de********@gmail.com wrote:
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.
Mar 22 '07 #10
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("=")?

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

Mar 23 '07 #11
<de********@gmail.comwrote in message
news:11**********************@p15g2000hsd.googlegr oups.com...
>
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?
Mar 23 '07 #12
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
Mar 24 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
7
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
6
by: harry | last post by:
Hi, I have a program that runs on multiple client pc's. Occasionally one or more of those pc's use VPN to connect to another corporate network. When using VPN they need to set proxy server in...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.