hello
i wanted to ask how to create a function that makes the insertion code search for an occurence that i will insert with a cin , instead of picking the first occurence
for example the array is arr[]={1,2,3,5,3,1,3}
there are 3 threes here , i want to get the index for the one i want using a cin , plz help me
Hey11
0
Newbie Poster
Recommended Answers
Jump to PostSo do you want to put in, for example, "3 2" and have it find the second occurrence of the value "3"?
Jump to Post@OP
How about this:
cin >> num; cin >> occuranceValue; for (int index = 0, count = 0; count < occuranceValue; index++) { if (arr[index] == num) count++; } return index; // shows the index in the array where the nth occurance of num is present.
Jump to Postplz help , whats wrong in the code ??
Here's what I see wrong:
1) Bad formatting, making the code hard to follow (see this)
2) Usingsystem("pause");
(
All 9 Replies
Fbody
682
Posting Maven
Featured Poster
Hey11
0
Newbie Poster
myk45
48
Posting Whiz
Hey11
0
Newbie Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
Hey11
0
Newbie Poster
Hey11
0
Newbie Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
myk45
48
Posting Whiz
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.