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
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.
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;
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"};
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?
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;
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.
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); }/>
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;
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.
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);
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.
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
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.
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.
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.
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.