C/C++ :: How To Find A Specific Value In Array

Mar 16, 2015

im having trouble with a function im writing. Its supposed to find the minimum value in an array and return the location of that value heres what i have so far :

int findLowest (int numb []) {
// findLow will hold the subscript of the lowest value in the array
int findLow = numb[0];
int x;
for (x = 0; x < 5; x++){
if (numb[x] < findLow)
findLow = x;
}
return findLow;
}

View 3 Replies


ADVERTISEMENT

C++ :: How To Find Path To A Specific Program

Feb 16, 2014

In my C++ program, lets call it menu.exe, I want the user to be able to run a specific program when selecting a specific menu, let's call this program cios.exe.

As the users of my program can have the cios.exe installed in any folder location, I need a way to first locate where the cios.exe is located and then start it with ShellExecute. My problem is : How do I find the path to where cios.exe is located in anyones PC as it can be installed it any folder location.

View 3 Replies View Related

C++ :: Iterate Through Container And Find Value Mapped To A Specific Key

Jan 14, 2014

A C++ container type called std::map is used to store elements that are formed by a combination of key value and mapped value. How do you iterate through this container and find the value mapped to a specific key?

View 3 Replies View Related

Visual C++ :: Find Specific String Of Lines In A Text File

Oct 15, 2013

I am trying to print a specific line from a textfile

e.g
I have a text file called info.txt and inside it contains the id,item name, price, quantity

Code:
1,shirt,100,10
2,pants,50,9
3,pen,20,8

I know how to find a specific word at the line in the file but how do I find and print out the specific line e.g(print out just the entire contents of line 2)?

Code:
string temDescription;
ofstream fout;
int curLine = 0;

[Code].....

View 1 Replies View Related

C++ :: Specific Iterator Type - Find Distance By Simple Subtraction

Sep 24, 2014

I have a templated container that defines a forward iterator.

Calling std::distance on these iterators will generate code that will count the number of iterations it takes to get from the first parameter to the second, by repetitively incrementing.

Internally, the iterators can easily find the distance by a simple subtraction.

What I want to do is overload std::distance for these iterators so that it will take advantage of the simple calculation rather than repetitive increments.

The simple solution of course would be to make the iterators random access, but this would require that they support functionality that is not 'logical' for the container. Access to the container only makes logical sense when iterating one item at a time in the forward direction.

Code:
#include <iterator>
template <typename T>
class Container {
public:
class iterator : public std::iterator<std::forward_iterator_tag, T> {

[Code] .....

View 2 Replies View Related

C++ :: How To Make Specific Character Show Up Specific Amount Of Times

Mar 5, 2013

How do I make a specific character show up a specific amount of times?

Like I am generating a random number then I need to make "|" show up that many times on the screen.

View 1 Replies View Related

C/C++ :: Censoring Specific Word Within Array?

Oct 3, 2014

What the program does: I am trying to code a program that makes the user enter a phrase, then censor the word "darn" if the user entered it.

The program is working very well; it will censor any "darn" words the user enter, by replacing it with ****.

The problem: I need to enter a phrase just once, before the program prints out the phrase the user had entered, The phrase purpose is to tell: either the phrase was clean, or it had "darn" within it.

I tired:

1-Defining an integer (counter=0;), and adding (counter=counter+1;) in the first while loop, when I am storing char's into my array. Then, adding if statement (if index==counter) for the phrase I need to print before printing the user entry. It should print out the statement only if (counter==index), because counter would still have the count of user entry. -> didn't work, the phrase won't print.

2- Making the previous step within its' own loop. -> It stopped printing the user's phrase.

Tools I can used : If statements, while loops.

Here is my code: (Ignore the phrases within /**/, they are just the statements I want to print)

#include <stdio.h>
int main() {
char phrase[1001]; // Creats 1000 array ( max. number of letter the user could enter is 1000).
int index=1; // Act as counter, which would refer to a character in the array.
char cur; // Identify cur, which will be used to store characters into the array (phrase).
printf ("Please enter a phrase:

[code]....

View 9 Replies View Related

C++ :: Deleting Specific Class Object In Array

Jan 23, 2013

I am trying to delete a speific element in an array of class objects. i am overwriting the element i waant to delete with the element after it. My algorithm works but the output is not correct, after debugging it seems my objects just dont copy, is there a way to copy a class object, i have looked up copy constructors and attempted to write one but it does not seem to have any effect on the output.

below is my code

class user {
string firstname, lastname, currentteam, position, status ;
int age ;
public:
user() {};

[Code] .....

View 4 Replies View Related

C :: How To Find Maximum Value Of Array

Oct 29, 2014

Any way to determine the highest value of an array I created with random numbers. I am confused because the array needs to be initialized in the main, but populated in a function. I was able to populate it using a pointer variable and my results came out good for the initial array values and elements.

In order to figure out the max, I think I would need the results of the populated array. How do I do this when the populated array is stored in a pointer variable? Would I need to create a pointer to the first pointer I created? I tried creating another pointer to the initial array and printing that, but my results were not good.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

[Code].....

View 10 Replies View Related

C++ :: How To Find First Element In Array

Oct 7, 2013

Lets assume, I use array of 100 the i input 50 element and now i want to find which one is first in array... without using pointer ...

View 2 Replies View Related

C++ :: Find Median Of Array?

Jul 4, 2013

I am trying to find the median of an array in c++.

This is the array that I would like to find the median for.

scores[14] = {62,70,98,71,81,99,74,80,73,88,73,72,95,71};

View 5 Replies View Related

C++ :: How To Find Mode In Array

Feb 6, 2014

How do you find a mode in array? This is what i got so far. I put this after i sort the array

for (int index = 0; index < size2; index ++) {
//count[mode[index] - 1]++;
if (mode[index] == mode[index + 1]) // compare the first to sec array {
again++;
cout <<"This is number " << again << endl;
}
}

View 1 Replies View Related

C++ :: Find Highest Value Of Array

Nov 4, 2013

I am currently trying to make a simple method for an array that would find the highest value. here is currently what i got, but do not know what to change to make it correct.

double FindMax(double stock[], int size){
int size = stock.length();
int max = stock[0];

for(int i = 1; i < size; i++){
if (stock[i] > max)
{max = stock{i};}
}
return max;

View 3 Replies View Related

C++ :: Find GCD Of Array Of Numbers

Aug 25, 2013

I wrote this GCD function to find gcd of an array of numbers . Here is the code:

long long GCD(long long min,int loc,long long b[]) {
for (long long i=min;i>0;i--) {
bool p=0;
for (long long x=0;x<loc;x++) {
if (b[x]%i!=0)

[Code] ....

Its returning wrong answers. When i tried 6 14 it returns 6

View 6 Replies View Related

C/C++ :: How To Find All Possible Combinations In 2D Array With Given Sum

Feb 26, 2015

How to find all possible combinations of coordinates on a 2d grid with a given sum. The sum is not fixed!

E.g. N=nxm=25 thats our grid.

The sum=distance between points on a grid.

For two points distance=|(x1-x2)+(y1-y2)| point A(X1,Y1) B(X1,Y1)

My interest is to know how to find the combinations of coordinates with a given sum, it doesn't matter how many points are there.

If i enter the sum e.g sum=7 and the program has to show all possible combinations which gives the sum of 7 the number of point does not play in row they might be two or maybe more.

View 4 Replies View Related

C :: Find The Length Of Char Array

Sep 25, 2014

I am working on a c-programm. In this program I have to convert the amount of money I read on two variables into the corret format. I got Euros and cents on 2 ints. But now I want to add both of those variables in a String (char array). Also i want to find out the length of the new char array.

View 2 Replies View Related

C :: Find The Value Occurs Most In 8 Integer Array

Jan 30, 2015

I want to find the value occurs most in an 8 integer array. Here is the code that I have. It does compile, but has not been tested.

Code:
int POLL (int *RANGE_ARRAY) {

int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int j = 0;
intk;

[Code] .....

Does this look right or is there a better way of doing this?

View 12 Replies View Related

C :: Find Prime Numbers - How To Use Bit Array

Aug 19, 2013

I wrote some code for class to find prime numbers.The teacher says that I need to revise my code with the requirement below: use a bit array to store the prime number checking. The bit array will also be in the heap. Use the max value of an unsigned 32-bt integer (UINT_MAX) to be the maximum size of the prime number you want to check.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <getopt.h>
#include <ctype.h>
#include <stdint.h>

//function to set all non-primes to 0
void *zero_multiples(void *threadid);

[Code] .....

View 4 Replies View Related

C :: How To Find Duplicates In Array Of Structures

Jul 21, 2014

I have an array of structures with structure def that looks like.

Code:
struct {
char * name;
char * school;
int age;
}

there are multiple people with same name but different ages so i want to list them like.

Name.
age 1
age 2 and so on

The array is sorted by name already.

View 3 Replies View Related

C++ :: Find First 10 And Last 10 Words Of String Array

Jan 26, 2015

I got a homework that require to count number of words in a text file and also display the first and last 10 words of the text file to the console. I have finished the counter problem and now I struggle showing the first and last 10 words.

#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int tokenize(string sentence, string tokenizedWords[]);

[code]....

View 2 Replies View Related

C++ :: Find All Unique Triplet In Given Array With Sum Zero

Feb 26, 2015

I got all unique triplet from below code but I want to reduce its time complexity. It consist three for loop. So my question is, Is it possible to do in minimum loop that it decrease its time complexity. code will be execute in minimum time.

#include <cstdlib>
#include<iostream>
using namespace std;
void Triplet(int[], int, int);
void Triplet(int array[], int n, int sum) {

[Code] .....

View 7 Replies View Related

C++ :: Find Smallest Number In 2D Array

Oct 21, 2014

I need to generate a grid of 10x8 and fill it with random numbers (max 70), then i need to find the smallest number within the random numbers generated and my "findSmallest" function does not seem to work and i do not know how to make it work...

Here my Code:

include <iostream>
using namespace std;
int main() {
int row=0;
int col=0;
int ArrayGrid [9][11];
srand(time(NULL));

[Code] .....

View 4 Replies View Related

C/C++ :: Couldn't Find Index Of Array

Feb 12, 2014

I have problem with find the index of the following array.

int minimums[2]={201,201};//first initialize both to greater than maximum allowed

for (int index = 0; index < 200; index++) {
if(find_array[index] < minimums[0]) {
minimums[0] = find_array[index]; //Lowest number

[Code]....

View 14 Replies View Related

C/C++ :: Using Function To Find Mode Of Array?

Oct 20, 2014

My code seems to find the mode of the array I input sometimes. Sometimes it gives me the wrong number or multiple numbers. It just all depends on what is number is inputted into the array. I don't know what the problem is. I tried looking online and editing many times and can't find the answer. Maybe I'm overlooking something or doing something wrong. Here's my code.

#include <stdio.h>
void readArray(int arr[], int length)
{
printf("Enter data:
");

[Code].....

Maximum: 15
Mode: 2

As you can see the mode is clearly not 2 and I do not know why.

View 8 Replies View Related

C/C++ :: Program To Find Majority In Array?

Sep 13, 2014

I have written a program that will input a text file named "inarray.cpp", which contains 10 numbers each separated by a comma, into an array and display the majority on the screen. I am having trouble reading the file in the correct way. For example the numbers have to be on their own separate lines with no commas for my program to work.

ie...

I need to read in 1,2,3,4,5...
but instead i am reading 1
2
3
4
.
.
.

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

[Code]......

View 1 Replies View Related

C/C++ :: Find Mode Of Sorted Array

Sep 14, 2014

I've been working on my program to find mode of sorted array. But the program didn't return the res

#include <iostream>
using namespace std;
int main () {
cout<<"Enter the size"<<endl;
int size;
cin>>size;
int data [size];

[Code] ....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved