C/C++ :: Traversing A List Comparing To Compare Values?

Apr 22, 2014

I have a method that traverses a list to compare a number from the list to user input from elsewhere in the program. I have tried a few different things and I am probably overlooking something simple but my problem is my if statement is executing the else statement every run no matter if the input matches. This function is to return the location in the list that the num matches. -1 if no match, 0, 1, 2, otherwise depending on the number of nodes.

int NumberList::find(int num)
{
int temp = 0, count = 0;
ListNode *nodePtr;

[Code]....

View 2 Replies


ADVERTISEMENT

C++ :: Traversing A Linked List

Mar 30, 2013

When I am traversing a linked list ...i suppose we can do it only with pointers

like p is a head node pointer then

p
p->next
p->next->next
p-next->next->next

so on represents a link...

if i have to pass head node as struct variable itself...can i traverse a link using dot operator??

p and p.next and how to retrieve third and remaining links through this method if we can traverse like this???

View 1 Replies View Related

C++ :: Traversing Linked List (Minions)

Jan 29, 2015

I have been trying to create a linked list of "Minions" where each has x coordinates, y coordinates, wp (weapon power), and a pointer to next minion.

the code:

#include<cstddef>
#include<iostream>
using namespace std;
struct minion{
int x;
int y;
int wp;
minion* next;

[Code] ....

Problem is: I made 3 for loops in main, first one to display the current weapon power which expected to output 10 10 10 (initial set weapon powers), 2nd for loop increases their weapon power (for whatever reason, a level up or something), third loop should display the new increased weapon power.

BUT, what i get is 10 and below it 30. looks like min4's wp only increased. There must be something wrong i am doing while i try to loop through my linked list and i cant figure it out...

View 3 Replies View Related

C++ :: Traversing Doubly Linked List

Feb 26, 2014

I have no problem traversing at both forward and backward but not simultaneously. I can traverse forward, and traverse again forward with no problem. I can also traverse backward and traverse backward again with no problem (take note this is by not exiting the program). Without exiting the program, with the same datas inputed, if i traversed forward, i cannot traverse backward (it only gives me infinite loop of the first data) and vice versa.

#include <iostream>
using namespace std;
struct Node {
int data;
Node *next;
Node *prev;

[Code] ....

View 2 Replies View Related

C++ :: Traversing Both Ways In A Doubly Linked List?

Mar 22, 2015

I've been working on a doubly linked list project for my Data Structures course. I've got everything to work so far, except for traversing in both directions. Traversing in the forward direction works fine, but when I try choosing to traverse backwards (starting from the tail of the linked list), it just says that the value is not in the list. That being said, the output looks like this:

This is not true, as you can obviously see, the value 26 is in the list, just two elements to the left of the tail (the value in tail for this particular case, obviously, is 36). The output should have been something like, "The value 26 was found 2 elements from the tail node". Here's the code for the findValue() function:

Code:
template <typename T>
bool LinkedListX<T>::findValue()//bool valueFound {
int traverseDirection = 0;
bool found = false;
int key;

[code]....

View 6 Replies View Related

C# :: Making String Equal Many Different Values Then Compare Those Values

Dec 18, 2014

I was wondering if this was even possible and if so, how do I do it.

else if (speech.ToLower().Contains("truck") && speech.EndsWith(number))
{
Here I would like to see if my speech had ended with any of the values i would have stored in the string "numbers". If it did, I would like to just take the value and add it to a new string called whatever
}

I have tried this a million different ways and I cant get it to work. I'm not even sure how I would go about storing tons of different numbers in one string, or if that's even possible.

View 10 Replies View Related

C/C++ :: Loop Not Comparing Values Correctly?

May 12, 2014

So, I have the beginnings of a rock paper scissors game which i have created before in Java, and i am attempting to create it in c++.

Problem is, the function "int checkConvertInput" containing a loop to make sure input is valid, is not exiting the loop. As far as i can see the two strings are not comparing. Is there a library function for this? I know C had strcmp but i am not sure if it applies here.

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int checkConvertInput(int playerSign, string signs[]);

[Code] ....

View 6 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++ :: How To Compare Two Double Values

Mar 24, 2014

I want to compare two double values

double x = 3072.00000000;
double y = 3072.0000000;

when checking with if its not working

if(x==y) it not working

View 1 Replies View Related

C/C++ :: Comparing Element Values In Dynamic Parallel Arrays

Oct 30, 2014

I've been working on an assignment that deals with newspaper advertisements. I have two arrays:

categoryCode (the code for the advertisement's category such as pets, cars, etc) and
numWords (number of words in the ad).

The arrays are dynamic.

My assignment has the category listed each time there is an ad associated with it and then its number of words for that ad. If this were a real-world issue I would want my output to list each category only once despite how many ads were in it, list how many individual ads are in the category, and its total number of words for the ads in that category. When using parallel arrays, is there a way to do this?

Let's say I have categoryCode with three elements {5, 5, 7} and numWords {10, 12, 15}.

How would I make the numWords add together only when the categoryCode values are the same?

I would want the output to print:
Category 5 Ads 2 Words 22
Category 7 Ads 1 Words 15

rather than how my instructor is having us do it like this:
Category 5 Words 10
Category 5 Words 12
Category 7 Words 15

I think I'm getting hung up because my mind is confusing the element's location in the array with the element's actual value and I'm probably making this harder than it should be. How would I compare the categoryCode values in a dynamic array? If it were a fixed size I think I could just compare categoryCode[0] to categoryCode[1] and so on, right? But in this case I'm not sure how I would go about that.

View 6 Replies View Related

C++ :: How To Compare Values Of Two Objects Of Same Class

May 27, 2013

Running into a snag in my program. I can't seem to figure out how to have an object of a class be able to look at all the other objects of its own class.

Reasoning being, I'm working on a game with multiple ships flying around in the same space. Each ship is a class.
Each ship has an x and a y, and needs to compare the angle and distance of other ships' x and y coordinates to see if they're visible on the same screen.

How to tell an object to look at objects of its own class.

Here's some code:

common.h

#ifndef COMMON_H_INCLUDED
#define COMMON_H_INCLUDED
int dist(int x1, int y1, int x2, int y2);
int get_info(int which);

[Code] ....

Basically, I just don't know how to properly write a function, call, or how to get the info I need, to the Player::get_closest() function so that it can see the other play objects.

View 7 Replies View Related

C# :: Compare Values From User Input

Nov 3, 2014

What do I put to have UserNumber == 1-10? In other words I want it to say...

if UserNumber equals 1 through 10 <<<<This is where I'm having the issue.

Do this
Else
Do this

namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Start:
Console.WriteLine("Please enter a number between 1 and 10");
int UserNumber = int.Parse(Console.ReadLine());

[Code]...

I got it.

View 8 Replies View Related

C :: Compare Integers With Hard Coded Values Goes Wrong In DLL

Mar 6, 2015

I am about to transfer a project I have written in Applescript and Objective C to Excel/VBA/dll. I have started with the Objective C functions that I want to place in a dll and call via VBA.

The Objective C is C with a thin dusting of special Obejctive C code to have it talk with Applescript and the rest of the project so in theory it should be easy to make dlls written in C from it.

But I have already problems with the tiniest of all functions. I am sure it can be done more effectively but right now I need to know WHY it doesn't work if I am ever going to be able to transfer the much larger functions from Objective C to C.

Here is my original Objective C code:

Code: -

(NSNumber *)game:(NSNumber *)games gamechange:(NSNumber *)gameskifte
{
int gamesab = [games intValue];
int gameskifteab = [gameskifte intValue];

[Code].....

View 5 Replies View Related

C/C++ :: Compare Two Arrays And Print Out A List Of All Songs Without Repeating

Mar 11, 2014

I have two arrays:

const char *mymp3list[15] = { "Song 1", "Song 2", "Song 3", "Song 4", "Song 5", "Song 6", "Song 7", "Song 8", "Song 9", "Song 10", "Song 11", "Song 12", "Song 13", "Song 14", "Song 15" };
const char *myFriendsmp3list[20] = { "Song 1", "Song 2", "Song 3", "Song 4", "Song 5", "Song 6", "Song 7", "Song 8", "Song 9", "Song 10", "Song 11", "Song 12", "Song 13", "Song 14", "Song 15", "Song 16", "Song 17", "Song 18", "Song 19", "Song 20"};

And I want to compare the two arrays and print out a list of all the "songs" without repeating any.

I've figured out how to print the just the duplicates using:

for (int count = 0; count < SIZE1; count++){
for (int i = 0; i < SIZE2; i++){
if (mysonglist[count] == friendsonglist[i])
cout << mysonglist[count] << "";
}
}

But I'm stumped on how to print a full list containing no duplicates.

View 4 Replies View Related

C :: Pull System Information And Compare Results With Predefined List

Feb 9, 2014

How to pull system information and compare it's results with a predefined list.

I know the second part, how to pull system information. Like what CPU/GPU/Motherboard the system that the program is run on has.

View 11 Replies View Related

C++ :: List Of Objects - Read Information From Each Object To Compare To User Input Prompt

Apr 19, 2013

I have a list of objects that I need to read information from each object to compare to a user input prompt.

#include "Passenger.h"
#include "Reservation.h"
#include "Aircraft.h"
#include <iostream>
#include <fstream>
#include <string>
#include <list>
using namespace std;
//Function Prototypes
void flightRoster(list<Reservation>&);

[Code] ....

View 1 Replies View Related

C++ :: Traversing Array Of Lists Of Objects?

Nov 13, 2013

I am working on building a graph of a maze problem using an adjacency list and my own custom class Node.

Each Node has a vNum and jumpAmount integer variable, the vNum is the unique key.

If I have an array of lists of Node objects declared by: Code: forward_list<Node> adjacencyList[10] I skip the 0 row and only use 1-9. It makes more sense logically for my program and Im not worried about wasted memory at this point.

How could I go about traversing and outputting member variables for all the Nodes in each list in my array?

Say my code builds the following adjacency list:

Code:
1 -> { 2, 3, 4, 7 }
2 -> { 1, 3, 5 }
3 -> { 1, 2, 6 }
4 -> { 1, 5, 6, 7 }
5 -> { 2, 4, 8 }
6 -> { 3, 4 }
7 -> { 1, 4, 8 }
8 -> { 5, 7, 9}
9 -> { 8 }

where the values in brackets are the nodes that have an edge with the ith row node. Had to put it in code tags for the thread to be allowed to post.

I am using the forward_list library for my list functions and this is where my problem arises. The cplusplus.com - The C++ Resources Network website iterates through the list using:

Code:
for ( auto it = mylist.begin(); it != mylist.end(); ++it )
std::cout << ' ' << *it;

Obviously this works for ints, doubles, etc, but not objects with member variables. My attempt to replicate this code for my problem looks like:

Code:
for( int i = 1; i < 10; ++i ) {
cout << "Node " << i << " -> { ";
for( Vertex it = adjList[i].begin(); it != adjList[i].end(); ++it )
{
cout << it.getVNum() << ", ";
}}

I have to come up with user defined conversions for this to work and I have never done such a thing. Is there a way to go about doing this to avoid user defined conversions, because if there isnt I feel like attempting to do this specific problem might be a little too difficult for someone who hasnt defined any custom conversions.

Potentially, I could write my own List class and have a next pointer member variable that points to the next object in the list and use that to use a dot reference to a get function to display member variables. This is how I learned linked lists back in my Data Structures class. However I am trying to avoid that for the time being, as that would be a lot more code to implement rather than just figuring out how to use the forward_list library.

View 4 Replies View Related

C++ ::  finding Max Value From A List Of 10 Values?

Jan 26, 2013

i am trying to find the max value from a list of 10 values. here i have stored the double values for prices of items in numVal.There are 10 values in numVal i would like to find the max and min value of these numbers. getPrice(1) returns the ten double values.

for(int i = 0; i < store.size(); i++) {
double numVal = this->store[i].getPrice(1);
}

View 2 Replies View Related

C++ :: Storing A List Of Values?

May 1, 2014

I have a list of integers that i wish to store in some kind of array. However i do not know how many integers are needed to be stored each time i run my program so i therefore cannot define a size for my array.

View 2 Replies View Related

C++ :: Assigning List Of Values To Vector?

Mar 30, 2013

I am trying to assign a list of values to a vector:

vector<string> words;
words[] = {"one", "two", "three"};

This does not work. How can I accomplish it?

View 5 Replies View Related

C++ :: How To Delete All Values In The Linked List

Feb 15, 2012

I have made this program for linked list, but i have one problem with it. I want to make a function that will delete all same values I inuput in the list.

Example: if user inputs 5 I want to delete all 5 for the list. I have tried doing this with the loop inside regular function that erase single value.

This is function that erases single value:

Code:
void list::Delete (int a) {
node *temp=head;
if (temp==NULL)
return ;
if (temp->getNext()==NULL) {
delete temp;

[code]....

View 3 Replies View Related

C# :: Linq To XML - Populate List With Multiple Values?

Aug 26, 2014

I have an XML document, formatted as such:

<?xml version="1.0" encoding="UTF-8"?>
<Books>
<Bookmark Name="1984" Folder="C:UsersmillerDownloads1984 (George Orwell) - Audio Book" Time="00:43:58.4080000" Chapter="0" />
</Books>

Each Element named Bookmark has 4 attributes, Name, Folder, Time, and Chapter.

I'd like to be able to just put all of them in ONE type of container, without making multiple lists... Is there any way, using Linq to XML, to maybe add all of these values to a Tuple?

View 14 Replies View Related

C# :: Linked List Storing String Values

Apr 8, 2015

I am creating a to-do list application and to store the tasks on the list, I am trying to create a linked list. the code for it so far is as follows:

public class Node //Class for nodes which make up a linked list {
//Declaring the data to be stored in each node and next variable to point to the next node
public string title;
public string description;
public string priority;
public string finish;
public string complete;

[Code] ....

The problem with this arises when I try to create a new node from another class like so:

createForm create = new createForm(); //Creates an object reference to createForm
create.ShowDialog(); //Shows the createTask form for creating a new task
//Declares variables and stores the return value of methods in createForm
string _title = create.getTitle;

[Code] ....

The variables _title etc.. all store values from text boxes as string. However, the code creating the object says the the variables cannot be implicitly converted from type 'string' to 'int'. Why this error is happening??

View 3 Replies View Related

C++ :: For Loop To Find Index Values - Reference List

Mar 18, 2013

im using a for loop to find the index values of the tied high scores and store them into string list then reference list in the second for loop to output it to screen however it isnt letting me use an array with index i as an index its self.

void printHighest(Student s[], int length){
int index;
string list[10];//you're never going to have more than 10 people with a tieing highscore.
index = findMax(s, length);

[Code] ....

For the time being I simply removed the idea of string list and just put the contents of the second for loop into the if statement above it. However, I am still curious as to if I can reference an index of an array in an index of another array.

View 1 Replies View Related

C Sharp :: How To Loop Through Array List For Unique Values

Aug 19, 2012

I am grabbing data from three entities and want to grab a field value in each of the entites and place it in an arraylist. What I would like to do is loop through the arraylist for all the values and do something for each value only once. If the value in the array list is repeated, I want to not do anything for it and continue till the end. Basically, I loop through all the values do something for each value and skip over the repeated value if I already did something.

View 1 Replies View Related

C++ :: Debug Function For Application - Output Values List

Jul 11, 2012

I'm trying to write a debug functions for my application so I can see all the values I like to. My goal is it looks like this:

Code:
void Debug(std::message, ...)

So that I can call it like this:

Code:
Debug("Error: %i, %i", 34, 35);

How I can work with %i, or if there are better solutions. This is what I've so far (not much), just a basic idea:

Code:
void Debug( std::string message, ...) {
va_list list;
va_start(list, message);
??? va_arg(list, ?? );
va_end(list);
// here message should contain everything and be ready for output ?
cout << message << endl;
}

View 3 Replies View Related







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