Newbie here. i need to create a program with this output:
Enter 5 values: 3 4 5 7 9
Enter a number to search: 4
4 found in location 2

Anyone who can help me on this?

Tnx,
Claire

mvmalderen commented: Double post ! +0

Recommended Answers

All 18 Replies

You should put the numbers at some place... and check every one of them...

That is an extremely easy solution.

Use a for loop. And show some freakin effort!

Read your text book!!

I mean please at least TRY.
skatamatic, said use a for loop. Go search what is a for loop etc.
I will elaborate a little.
Use a for loop to accept all number in a array.
Use another for loop to check weather each of those elements is equal to the searched value.

>And show some freakin effort!
>Read your text book!!
>I mean please at least TRY.
If it's simply a matter of being vague, there's no point in biting heads off when you could just as easily ask for more information, like "what have you tried so far?" or "what are you finding difficult?". Please reserve the snarky comments until you're sure the OP deserves it or you'll just come off as a jackass.

I can't find a reason why not to thrash any one like that !!.

And also, I gave him a solution too........ Not one of those who just barks off for nothing!!

I can take back my "I mean please at least TRY." but I wont take back my "Read your text book!!"

Besides,(of topic) your pictures just suits you :) and I like the way you speak :D (you cant always prove others wrong LOL)

>I can't find a reason why not to thrash any one like that !!.
I can think of a few likely ones, otherwise I wouldn't have commented. Not the least of which is the usual belief beginners have that the rest of us can divine the exact problem they're having without being given specific information. That's not a crime by any means, and bitching about effort is the wrong response.

p.s. You can't take back something once it's said. I've tried, and it doesn't work.

>p.s. You can't take back something once it's said. I've tried, and it doesn't work.
Hmm, you are right on this, I also just tried but it didn't work.

And here is why I thrashed him :http://www.daniweb.com/forums/thread178893.html << a same post with same remark.
And look what he said on this post : "pls give me a program on this, i cant seem to make the program work with regards to the location thing."

>I can't find a reason why not to thrash any one like that !!.
I can think of a few likely ones, otherwise I wouldn't have commented. Not the least of which is the usual belief beginners have that the rest of us can divine the exact problem they're having without being given specific information. That's not a crime by any means, and bitching about effort is the wrong response.

p.s. You can't take back something once it's said. I've tried, and it doesn't work.

Hey thrashing the thrashers is just as hypocritical as hating all racists.

Thanks for that skatamatic. You achieved the desired effect of me chat raping you without any action on my part. :icon_rolleyes:

If either of you have any further comments for me, I'll direct you to my PM so that we don't drive the OP's thread too far off topic.

Narue, I sent you PM,
I think you are kind of protected by some spam filter hence would not receve my PM. If you can't do tell me. and yes........... No more off topic posting.

here's the program i made and it won't work the way it should

#include<stdio.h>
main()
{
int no[5];
int c,d,loc;
printf("\n Enter 5 values:");
for(c=0;c<5;c++)
{
scanf("%d",&no[c]);
}
printf("\n Enter a number to search:");
scanf("%d",&d);
loc=0;
for(c=0;c<5;c++)
{
if(d==no[c])
loc=loc+1;
}
printf("\n The location is: %d", loc);
getch();
}

here's the program i made so far....

#include<stdio.h>
main()
{
int no[5];
int c,d,loc;
printf("\n Enter 5 values:");
for(c=0;c<5;c++)
{
scanf("%d",&no[c]);
}
printf("\n Enter a number to search:");
scanf("%d",&d);
loc=0;
for(c=0;c<5;c++)
{
if(d==no[c])
loc=loc+1;
}
printf("\n The location is: %d", loc);
getch();
}

Hope your all calm now. Sorry for my bad english. I actually made a program and my problem is what logic i should be using so i could show the location of the number. The last output always display 1 as the location. Sorry again, you didn't have to argue on this, I actually made a mistake not posting the program i've been trying to run.

#include<stdio.h>
main()
{
int no[5];
int c,d,loc;
printf("\n Enter 5 values:");
for(c=0;c<5;c++)
{
scanf("%d",&no[c]);
}
printf("\n Enter a number to search:");
scanf("%d",&d);
loc=0;
for(c=0;c<5;c++)
{
if(d==no[c])
loc=loc+1;
}
printf("\n The location is: %d", loc);
getch();
}

TNX,
Claire

commented: The topic was rubbish to begin with, now 3 consecutive posts of un-tagged code - sorry, I lost interest. -6
for(c=0;c<5;c++)
{
if(d==no[c])
loc=loc+1;<<< change it to loc=i;
}
printf("\n The location is: %d", loc);
getch();
}

Read my comment on the above code;
I dont think it is a C++ program. Looks more or less look like a C program.
Very bad
.
Please use code tags to post the code.
And don't start two thread for the same thing

for(c=0;c<5;c++)
{
if(d==no[c])
loc=loc+1;<<< change it to loc=i;
//But where is i,the control variable is c
//Should be loc=c

This would certainly work if all the numbers are distinct,else you 'll get only the last occurrence of that number in the 'loc'

>But where is i,the control variable is c
Yeah, never mind. I overlooked it.
>else you 'll get only the last occurrence of that number in the 'loc'
Yes, he is right. You should perhaps issue a break statement after loc=c;

i used loc=c+1 instead.
Tnx for the help! It worked. Sorry for the fuss i made.

Thanks for that skatamatic. You achieved the desired effect of me chat raping you without any action on my part. :icon_rolleyes:

If either of you have any further comments for me, I'll direct you to my PM so that we don't drive the OP's thread too far off topic.

Did you just say you chat raped me? That's a little obscure.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.