C/C++ :: Iterate Through Array And Search For A Number That Was Stored By User

Nov 23, 2014

So I have an issue with a homework assignment that I am coding. I am attempting to get a function to iterate through an array and search for a number that was stored in an array by the user. So far I can take the number, get the numbers displayed but in my menuChoice2 function, for some reason the program is not confirming whether or not the number is entered, and is only telling me that the number has not been found, instead of confirming that the number is in the array.

Here is my code thusfar:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// Variables that are Globally declared
int menuChoice = 0;
int usernum[1000] = { ' ' };

[Code] .....

To be clear I am not getting any errors but something is telling me that the error is in the formatting of menuChoice2.

View 14 Replies


ADVERTISEMENT

C++ :: Search User Input Number In Array Filled With Random Numbers

Nov 6, 2014

I need to create A program That makes a 12x10 Array Grid Filled With Random Numbers From 0-99.

Then I need To Allow The User To Input A Number Between 0-99 And Then The program will then search through the array and count how many of the users number there is inside the array.

Code:

#include <iostream>
using namespace std;
int main() {
int input;
int number;
int row=0;
int col=0;
int Array [12][10];

[Code] ....

View 1 Replies View Related

C :: User To Enter 4 Integers Which Get Stored In Array

Mar 3, 2014

For my code, I want the user to enter 4 integers, which get stored in an array. Here are the lines I wrote relevant to this part:

Code:
printf("Enter 4 integers:
");
scanf("%d %d %d %d," &a, &b, &c, &d);
z[4] = { a, b, c, d};

Would this be correct?

View 5 Replies View Related

C :: Can't Print Number Stored In Array

Jan 12, 2015

when i compile and run it it gives me the number 0 and not the proper number stored in array.

Code:

#include <stdio.h>
int main()
{
int myArray[11] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
}

[code]....

View 4 Replies View Related

C/C++ :: Compare Values Stored In First Array To User Inputted Values In Second Array

Oct 19, 2014

Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.

In order to fix this error: [URL]...

I had to change my array initialization to one with a star in front of it:

char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};

I also changed my 2nd array to one with a star in front of it: char *a2[20];

What does this mean exactly? Putting a star in front of an array?

Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:

cin>>a2[i];

View 3 Replies View Related

C :: Iterate Through A User Inputted Integer?

Oct 5, 2014

I need to allow the user to input an integer of any length and print out the word of each number in the integer. So the user would enter "324562" and then the output would be "three two four five six two". I'm struggling to understand the best way to do it in C. I know I need a loop that goes through the int but I don't know how to do it

View 7 Replies View Related

C++ :: Search In A Vector Array From User Input String?

Sep 30, 2013

How would you search in a vector array from a user input string?

ex: user input : "Hello"

output: search vector array and find the line that has the string "Hello" and output the array "Hello" is on?

View 1 Replies View Related

C/C++ :: Use Binary Search To Find A Number In The Array?

Mar 23, 2014

i'm trying to use binary search to find a number in the array but i dont know whats wrong with my code. When l enter a number which DOES exist in the array, everything is ok... but when i enter a number which does NOT exist in the array, i have problem...i cant exit the program, it just continues to run.Here is my code

int main()
{
int FirstPosition;

[Code]....

View 2 Replies View Related

C :: Linear Search Script - Calling Array Inside Of User Defined Function?

Jul 24, 2013

im tasked with creating a linear search script using functions on a 10 element array. the elements are to be supplied by the user as is the search target.

I understand how to create the array and gather that information from the user as well as howto set a variable for "target", this is what im calling it. Those two parts are simple enough.

I am not fully understanding the calling of an array in a function as a pointer. i semi understand the use of a pointer and howto call a normal pointer in a function. i also understand that an array is nothing more then a "special" pointer with a set of consecutive address blocks for the size of the array.

My first user defined function is simple enough

Code:
ReadArray(int A[], int size){
int i;
printf("Please enter %d integer numbers separated by spaces:
", size);
for (i = 0; i < size; i++)
scanf("%d", &A[i]);
}

Sso nothing out of the ordinary there. that should be a standard for loop and use of scanf, sadly prof has not covered ssanf or any of the other options so i am stuck using scanf for now. maybe someday down the line in a other program or after this course ill get the chance to learn about better options for gathering data from the user.

I am confused as to my next function:

Code:
void SearchArray(int A[], int target, int size);

I've not written any code here yet as im not sure if i should call the A[], or *A for the first type of the function?

If i call *A do i then use something like this for my search:

Code:
for (*A = 0; *A < size; *A++)
if (*A < target) or use A[] insteadA?

Code:
for (i = 0; i < size; i++)
if (A[i] = target)

View 6 Replies View Related

C++ :: Binary Search Function - Return True If Element Inputted By User Found In Array And False If Not

Nov 9, 2014

I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//binary search function
bool search (int array[], int item)

[Code] ....

Why my code does not fulfill it's purpose???

View 7 Replies View Related

C++ :: How To Get User Input To Be Stored In 1 Out Of X Variables

Dec 5, 2013

Making a game of checkers on C++ win32, visual studio

when i want a piece to move, i type:

cout << "What piece do you want to move? (C4)" << endl;

i type in 'cin' after to get the players input, but how do i get it to store the players input in a certain variable? im going to have a list of variables:

string a1
string a2
string a3

etc

so if the user types in a2, it automatically goes to that variable and then asks the user "where do you want the piece to be moved to?".

View 6 Replies View Related

C++ :: Write A Calculator - User Will Enter Terms And They Will Be Stored In Arrays

Jun 14, 2013

i'm trying to write a calculator. the user will enter the terms and they will be stored in arrays. i will be storing those terms in string arrays and then later turn them to double to work with them. but the user should be able to enter terms like sin(252) and the program should be able to recognize it and calculate it.

View 4 Replies View Related

C :: Version Number Stored In EXE File

Feb 24, 2015

I am/we developing in C and we have a number of different programs. We also have problem to keep track of different versions of a specific exe file.

Is there any way to add version number when build a file so the version is added in the properties.

I doing this in a MFC c++ project in a .rc file. Is there a way (or a similar way) of doing this in C? Here its stored in the details section with product version 6.0.8:

View 6 Replies View Related

C++ :: Multiple Quiz Program - Adding High Score For Each User Stored In Binary File

Jul 11, 2014

I am making a multiple quiz program. So everything is working fine, except for the part where i'm trying to add a highscore for each user which is being stored in a binary file. I have added a sample of the program containing the error. This isn't the actual program, which is very long.

class user { //The collection of all info pertaining to the users
char user_id[50];
public:
int hscore1;
user() {
strcpy(user_id,"NULL");
hscore=0;

[Code] ....

View 1 Replies View Related

C++ :: Iterate Through Char Array And Pull IP Addresses To Test If They Respond

Apr 8, 2013

I am trying to write a loop that will iterate through a char array in C and pull the IP addresses and test them to see if they respond. My ultimate goal is to have the first one that responds returned in the function, but the loop is not running correctly. It will run through right the first time, but then will start over again.

Code:
const char * getServer(char *svrList) {
char *srList;
srList = strtok(svrList, " ," );
printf("Contents of srList b4 loop: %s
", srList);
printf("Server List: %s
", svrList);

[Code] ....

Code output:
Contents of srList b4 loop: 1.1.1.1
Server List: 1.1.1.1
result is "1.1.1.1"
Hitting else loop
Contents of srList in else: 2.2.2.2
result is "2.2.2.2"
result is "2.2.2.2"
Contents of srList b4 loop: 1.1.1.1
Server List: 1.1.1.1
result is "1.1.1.1"
Hitting else loop
Contents of srList in else: (null)

View 14 Replies View Related

C++ :: Search For A Number When Vector Is In Order - Count How Many Times That Number Appears

Feb 6, 2014

In this program what i'm doing is to search for a number when the vector is in order, and count how many times that number appears, the problem is that count how many times the number does not appear, but when its appear the program stays in an "standby mode" and the cursor does not move.

int buscarNumOrdenado (int x [MAX]) //MAX is the define {
int num,d, LimiteInferior, LimiteSuperior,mitad;
d=0;
LimiteInferior = 0;
LimiteSuperior = MAX-1;

[Code] ....

View 2 Replies View Related

C :: User Input 6 - Array To Display Even Number From 0 - 6

Apr 5, 2013

If the user puts in a 6. I need the array to display the even number from 0 - 6. Right now what it does is it displays the first six even numbers. Okay as I'm writing this I'm starting to see where my problem might be..

Code:
void sumIntegers () {
int arr[50];
int i = 0;
int num = 0;
int sum = 0;

[Code] .....

View 1 Replies View Related

C++ :: Binary Search Or Linear Search For 3D Array

Oct 7, 2014

inputting a search array. I tried putting a binary search but I can't get it to work. everything else works up until I put the value I am searching for in the array, then it just crashes.

How it suppose to work: input 2 coordinates with a value each then it calculates the distance between them then it suppose to let user search the coordinates for a value and state if found which coordinate it is at.

#include "stdafx.h"
#include <iostream>
#include <iomanip> //for setprecision
#include <math.h>

[Code].....

View 3 Replies View Related

C :: Accept Input Number From User And To Convert It Into Array Of Integer

Oct 7, 2014

i was trying to solve a problem in SPOJ and what i wanted to do is to accept an input number from the user and to convert it into a array of integer.

Code:

#include<stdio.h>
int * toarray(int *num);
int main(void)
{
int testCases;
}

[code]....

But whenever i try to print the array in the main function i get only two value and the rest address

Code:

1//number of testCases
23456 //input number
6
2293452
4
2293700
1974439125

Process returned 0 (0x0) execution time : 4.152 s
Press any key to continue. However, if i tried to print the array from within the function, it prints the numbers just fine.

print the array elements from the main program, so that i would be able to go on with the rest of it

View 1 Replies View Related

C++ :: Array Searching - Display Highest And Lowest Number From User Input

Aug 26, 2013

I am having a problem printing out the results for my code, It is supposed to print out the largest and smallest value in the array, but keeps giving me a value not entered and I don't know why.

//This program lets the user enter 10 numbers and then display the highest and lowest number.

#include <iostream>
#include<stdio.h>
using namespace std;
int main() {
const int NUM_ENTERED = 9;
int number[NUM_ENTERED], highestValue = number[0], lowestValue = number[0], count=0;

[Code] .....

View 2 Replies View Related

C++ :: Force Variables To Be Stored In Char Array

Jan 7, 2015

I want to declare a char* array, and then make any future variables declared to be stored in a specific location within the char* array. Is this even possible, and if it is how would I go about doing it. (I plan on storing any primitive data type in it (not classes or structs), and they may signed or unsigned).....

View 12 Replies View Related

C :: Accessing Values Stored By A Pointer Into Array

Mar 7, 2013

I am writing a C program to access a string into an array from a pointer array in Visual Studio 2010. Program is given below:-

Code:

#include <stdio.h>
#include <string.h>
void main() {
char data_a[6],data_b[6]="ABcde",*ptr;
ptr=&data_b[0];
data_a[0]=*ptr;
printf("%s",a);
}

I am getting some junk character first and then my actual data on console window. I want to where I am getting wrong and how to resolve it.

View 4 Replies View Related

C++ :: Saving Text Stored In Array To TXT File?

Sep 2, 2013

how to save text stored in an array to a txt file. can sum1 how to save the text in an array to a file/txt file......

View 7 Replies View Related

C/C++ :: Force Variables To Be Stored In Char Array

Jan 7, 2015

I want to declare a char* array, and then make any future variables declared to be stored in a specific location within the char* array. Is this even possible, and if it is how would I go about doing it (I plan on storing any primitive data type in it (no classes or structs), and they may signed or unsigned). I want to be able to use the variables like any other variable, I just want the variable's address to be within the char* array.

I am trying to make a program that is similar to a virtual machine and an emulator put together, and it can only run one os (which will be hard-coded into to the program). The reason I wanted to do this is because it would be the easiest way to make sure that all variables in memory are in one contiguous block, that way the part that manages memory wouldn't have to store the locations of each variable (which would have been necessary for the virtual memory manager).

An example of what I am wanting to do is

char* ram [256]; // Address 0x00 to 0xff

// Code to make sure that new variables' addresses are in ram[] if necessary

unsigned short a = 5; // Gets stored at address 0x00

unsigned int b = a; // Gets stored at address 0x00+sizeof(a)

View 1 Replies View Related

C++ :: Find Greatest Difference Between Two Consecutive Elements Stored In Array

Mar 31, 2013

Develop a function that finds the greatest difference between two consecutive elements stored in an array. Develop a 9 element array of doubles to test your code. Print to the screen which two numbers have the greatest difference as well as the value of the difference. Finally include an overloaded version of the function that will work if the array is composed of integers. Include your code used to test this function.

View 8 Replies View Related

C++ :: Binary Search Tree Used With User Defined Class

Nov 29, 2014

I am working on a program that uses a class I created called Student. I want to be able to add different students to a Binary Search Tree, and use the student's gpa (grade point average) to compare students with each other and place them in the correct location in the Tree.

Student class:

#ifndef STUDENT_H
#define STUDENT_H
#include <string>
#include <iostream>
#include <iomanip>
class Student{
friend ostream& operator<<(ostream& out, const Student& stu);

[Code] ......

View 3 Replies View Related







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