C++ :: Make A Function To Return Placement Number

Mar 25, 2014

I have a class called items and stored in a vector as vector<items*> item.now I want to make a function to return the placement # that the item is stored at with a unsigned int. but if I don't find the item is there like a null unsigned int that can be returned.

unsigned int someFunc(vector<items*> item)
{
unsigned int size = item.size();
for (unsigned int i = 0; i < size; ++i)
{
if (item[i]->getItemName() == "sword")
{
return i;
}
}
//i need code here incase the item is not there
}

because the item might not be there and i would like to do a line if(unsigned int) do this code

View 19 Replies


ADVERTISEMENT

C++ :: Function Which Take An Integer And Return Number Of Digits In It

Jan 31, 2013

I want to write a function which take an integer and return the number of digits in it i.e

int i = 123456
func(i) {
some code
}

output
the number of the digits are 6

View 9 Replies View Related

C/C++ :: Take In Unsigned Number And Afterwards Return N-th Member Of Recursive Function

Mar 14, 2015

I'm having an issue with the following assignment:

Program is supposed to take in an unsigned number and afterwards return the 'n-th' member of the following recursive function:

f(1) = 1, f(2) = 2; f(3) = 3; f(n+3) = f(n+2) + f(n+1) + f(n), n>0;

When I worked with Fibonacci it was pretty easy since I just had to decrement the next member for each step. I used the following:

#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int fib(int n) {
static int memorize[MAX] = {1,1};
if(memorize[n])
return memorize[n];

[Code] ....

My main problem is that I have no visual of the current function, as well as the fact that it takes the f(n+3) = f(n+2) + f(n+1) + f(n), whilist I've only got f(n) to begin with.

View 5 Replies View Related

C++ :: Function That Should Return Number Of Digits In Integer Returns Last Digit

Feb 18, 2015

Code:
int exploder(int number,int array[]) {
int functi = 0;
int digit = number % 10;
while (number > 0) {

[Code] ....

View 2 Replies View Related

C++ :: Recursive Function - Take Number And Return With All Sevens Turned Into Eights

Apr 16, 2013

Task: Write a recursive function `seven_up` which takes a number and returns that number with all the sevens turned into eights.

- Example

cout<<seven_up(777)<<endl; //prints 888
cout<<seven_up(1234567890)<<endl; //prints 1234568890
cout<<seven_up(50)<<endl; //prints 50

- Hint: It's like removeFirst, except:

0. Base Case: If the number is one digit long, we don't want to erase it (by returning 0). Instead, riddle me this: When I have a one-digit number, what happens if I change all the 7's into 8's? Well, if the number is 7, it becomes 8, but otherwise it's unchanged.

1. Recursive Call: If the number is longer, then we strip off the last digit, figure out what the answer for the rest is (the recursive call on n/10), and then put the last digit back on the number when you're done.

Hint: You probably need to store the least digit (the n%10) and check if it's 7 separately.

#include <iostream>
using namespace std;
int removeFirst(int n) {
if(n<10)
return 0;
return 10*removeFirst(n/10)+n%10;

[Code] ......

I tried other algorithms but i don't get it.

View 14 Replies View Related

C++ :: While Loop - Use Non-recursive Function To Make Triangle Number Sum Of All Whole Numbers From 1 To N

Jul 31, 2014

My while loop is the problem. I want to use a non-recursive function to make the triangle number the sum of all whole numbers from 1 to N.

#include "stdafx.h"
#include <iostream>
using namespace std;
int triangle(int t);

[Code] ....

View 2 Replies View Related

C++ :: Randomizing String Placement In Array?

Jan 4, 2014

I need to take my string of 6 words, then scramble them into a different order, then output to the console. string line1[] = {"I", "Can", "Do", "That", "Hold", "My", "Beer"};

View 1 Replies View Related

C :: Will Return Root Statement At End Ever Return Value Other Than Value Passed To Function?

Mar 29, 2013

I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?

Code:

#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}

[code]....

View 4 Replies View Related

C++ :: How To Make Map Return Null When There Is Nothing At Certain Position

May 7, 2015

Code:
std::map<int, DWORD> unitColors;
DWORD color = unitColors.at(unit->id);

I want to use a color value of 0x00000000 when

a DWORD at unit->id of unitColors is unavailable.

Is it possible?

View 14 Replies View Related

C :: Return Number Of Bits Set To True

Jan 3, 2015

The task is to return the number of bits set to true.Here is my code:

Code:

int cardinalityBS(PBitSet _this) {
int s, counter = 0;
for(s = 0; s < 31; s++) {
counter += _this->bits & 1;
_this->bits <<= 1;
}
return counter;
}

[code]....

The code is not working, since whenever I set _this->bits to a number, it returns me the wrong result.

View 7 Replies View Related

C++ :: Random Number Generator - Return Value?

Oct 21, 2014

It seems as though my program is working great but I'm having problems with my random number generator. It keeps giving me a return value from the computer of scissors (or 3) for the computers random choice. What can I do?

//Purpose of Program: This program is meant to prompt the user to choose between 4 menu options.
// Each option will be the users choice of rock, paper, or scissors.
// the computer will then randomly generate a number and pit you against the computer.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

void user(int getUserChoice);
void comp(int getComputerChoice);
void winner(int UserChoice, int ComputerChoice);

[Code] ....

View 1 Replies View Related

C++ :: Pass 2 Arrays Into Void Function And Return Values To One Function?

Feb 12, 2014

I'm trying to pass 2 arrays into a void funtion, and return values to one function.

this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.

#include <iostream>
using namespace std;
void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize);
int main() {
int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189};
int numberCount[8] = { 0 };

[code]...

The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.

View 6 Replies View Related

C++ :: Return Maximum Frequency Number From Stack

Dec 17, 2013

I designed one mfc vc++application in which data received from udp is stored in file as well as in stack.I used stl for stack; it stored elements as per receiving order,but i want to return repetitive number from stack,how to use stack as function parameter & retrieve elements of stack as an array? I write code for push elements in stack given below.

<template< typename T > void pushElements( T &stackRef,int value) {
stackRef.push( value);
}/>

View 1 Replies View Related

C++ :: Program That Takes Two Complex Number And Return Their Sum?

Oct 25, 2013

you have been tasked to write a program that takes two complex number and return their sum.However the + operator will not worl with complex numbers and you figure you need to verload the + and the assignment opeartor=.Ypu have come across the program [URL]

implement it and the client code to see it rune for the following complex numbers:

c1=3.0-4i,c2=8+4i

i have 3 files,driver.cpp,Complexnumber.cpp and complexNumber.h

complex.cpp is as follows

#include <iostream>
using namespace std;
class ComplexNumber {
private:
double real;
double image;

[code]....

View 4 Replies View Related

C/C++ :: How To Make Multiple Subroutine And Return Multiple Arrays

Aug 17, 2014

how to make subroutines and return multiple arrays.Before that, i wrote my program on matlab. could my program to be structured as following?

<header>
initial value of program;
subroutine1() {
calculating the first work;
return 2 or 3 arrays;

[code].....

View 14 Replies View Related

C :: Main Function Does Not Return Any Values When Calling Other Function?

Jun 9, 2013

The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.

right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.

Code:

#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {

[Code].....

View 4 Replies View Related

C++ :: Remove / Rename Functions Works But Return Non-zero Number

Jan 13, 2013

My source works perfect.The problem is that the (remove(),rename()) functions works but return nonzero number, so they fails all the time.

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <fstream>

using namespace std;
int main() {
char array[100]={"1)open-write,2)open-read,3)rename,4)delete"};

[Code] ....

View 1 Replies View Related

C++ :: Multiply Number Of Seat And Ticket - Return Value Not Working

Dec 20, 2013

I have a code in here that u will multiply the number of seat and the number of ticket. I think I got the correct return value but it's still not working when i times it it always = 0 ...

#include<iostream>
#include<iomanip>
#include<string>
#include<stdio.h>
#include<fstream>
int getBill(int seat);
int getPos(char seat);

[Code] ....

View 14 Replies View Related

C++ :: How To Make Random Number To Be Different For X And Y

Sep 6, 2014

I got problem with the loop and Q(remains same = Q1 in output). How to make the random number to be different for x and y???

#include<stdio.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
int Random();
void Position(int z,int y);

[Code] ....

View 6 Replies View Related

C++ :: Keyboard Function That Is Called In Main Function To Make Shape Move

Jan 19, 2013

Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.

void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {

[Code].....

But when I try to call it, trying to copy my previous method,

glutKeyboardFunc(Player1.playerControls);

I get an error

error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member

I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.

View 2 Replies View Related

C++ :: Make The Program Generate A Different Number?

Apr 23, 2013

i wanna no if i can make the program generate a different number everytime you guess the number right and want to play again. it always generates the same number

#include <iostream>
#include <ctime>
#include <cstdlib>

[Code].....

View 9 Replies View Related

C :: Make Program That Asks User For Number?

Oct 15, 2013

So I'm trying to make a program that asks the user for a number and then prints a statement the same number of times the user entered. 3 different statements, using the 3 loops (for, while, and do while). I made the program but for some reason the statement from the do while loop goes off infinitely.

MY CODE:

The error:

View 8 Replies View Related

C++ :: How To Make Loop That Reiterates For Certain Number Of Players

Dec 11, 2013

Something that does something like this

at this point run a loop for all players, in this loop use random to determine the face and depending on the face run a loop (for roll again etc) or give next user the chance.

And this loop is 2-12 people, all rolling die.
They draw 3 die out of a cup of 12.
Then they roll the 3 die, getting fish, hook, or boot on each die.

View 1 Replies View Related

C/C++ :: Make A Program Which Can Work As A Backspace Number?

Dec 9, 2013

how work backspace key in c++.i want to make a program which can work as a backspace number

View 1 Replies View Related

C :: Make Program That Takes Number Input From Tuser?

Jul 27, 2013

I have to make a program that takes a number input from the user and prints the corresponding fibonacci sequence number. For example, for the input of 3, it should print 2 since the third term in the fibonacci sequence is 2.

I am not sure how to do this so for my attempt, I used the formula found in this website. A Formula for the nth Fibonacci number

Here is the program so far. It doesn't produce the correct output.

Code:

#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#include "math.h"

[Code]....

View 11 Replies View Related

C++ :: Program To Make A Table For Any Input Number - Do While Loop

Nov 27, 2014

Write a program to make a table for any input number and then continuesly ask to press y to print more table and if you press any key other than y then program must be terminate using while loop and do while loop. How to start or end with it.

View 2 Replies View Related







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