C++ :: Functions Does Not Return New Value

Jul 24, 2014

In my program below, in the getage and get level functions, if an incorrect input is entered, then the correct one is entered after, it still returns the bad input back to main.

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

[Code] ....

View 7 Replies


ADVERTISEMENT

C :: Functions With Different Return Type?

Feb 26, 2015

understand the below program.

Why I'm getting output y is 6.000000

Code:
#include <stdio.h>
int square(double a);
int main()

[Code].....

View 6 Replies View Related

C++ :: Functions Which Return Values

Nov 27, 2014

Write a function named cointoss that simulates the tossing of a coin.

When you call the function, it should generate a random number in the range of 1 through 2.

If the random number is 1, the function should display "heads".

If the random number is 2, the function should display "tails".

Demonstrate the function in a program that asks the user how many times the coin should be tossed, and then simulates tossing the coin that number of times.

Report the total number of heads and tails.

View 2 Replies View Related

C :: Code With Two Functions Just Won't Return Correct Result

Sep 23, 2013

Each time I run it I get in correct result. I even tried running with code from from my book and it failed aswell. The code from the tutorial worked some how. BTW I use DevC++ as my compiler.

Code:

/*
Fail results
Fail results
Fail results
*/
#include <stdio.h>

[code]....

View 2 Replies View Related

C++ :: RValue - References As Return Values Of Functions

Aug 13, 2014

I am trying to understand RValue-references as return values of functions. First let's consider a simple function, that transforms a string into upper case letters.

const std::string
toUpper(std::string orig) {
std::transform(orig.begin(), orig.end(), orig.begin(), ::toupper);
return orig;

[Code] .....

It compiles, but I get the output 0 . Here I am wondering why the code above does not move the substr correctly while the code below does (prints out 1):

const std::string&&
no_sense(std::string abc) {
abc = abc.substr(1, 1);
return std::move(abc);

[Code] .....

In both cases abc is a temporary object inside of the function and gets deleted after the function is left. But why does the second version work and the first one does not?

cat.substr(1, 1)

And as my last question. Why doesn't

return std::move(abc.substr(1, 1));

work?

View 3 Replies View Related

C/C++ :: Updating Value Passed Through Functions With No Return Statement?

Sep 13, 2014

I am supposed to update the value temp without using a return statement, or a global variable. I have never ran across a problem like this before and I am totally stuck. I think I'm missing something really simple and need a hint. Here is the code that was provided for "fixing".

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;

[Code]....

View 2 Replies View Related

C :: Testing Array Functions - Return Sum And Difference Of Two Matrices

Nov 10, 2013

I have these arrays in a driver to use for testing:

insert Code:

#include <stdlib.h>
#include <stdio.h>
#include "TwoD.h"
int main() {
/* Initialization of LCV's */

[Code] ....

If I want to test these functions in this header:

insert Code:

#ifndef TWOD_H_INCLUDED
#define TWOD_H_INCLUDED
#define MAX_SIZE 50
/* Structure defenition for TwoD */
typedef struct

[Code] ....

I am trying to perform columnSum and rowSum, as well as twoDadd and twoDSubtract using the arrays defined in my driver. How would I do that using A and B in my driver?

View 8 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 :: 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++ :: Return By Reference - Statement Doesn't Return Value Of N

Jan 11, 2015

From the page: [URL] ....

#include <iostream>
using namespace std;
int n;
int& test();

[Code] ....

Explanation

In program above, the return type of function test() is int&. Hence this function returns by reference. The return statement is return n; but unlike return by value. This statement doesn't return value of n, instead it returns variable n itself.

Then the variable n is assigned to the left side of code test() = 5; and value of n is displayed.

I don't quite understand the bold sentence. Shouldn't value of n and variable n be the same?

View 8 Replies View Related

C/C++ :: How To Access Linked List Functions From Stack Class Without Functions

Mar 20, 2014

I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.

We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.

As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.

NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.

Stack.h

#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;

[Code]...

View 3 Replies View Related

C/C++ :: Array Of Functions Pointing To In Class Functions With Arduino

May 3, 2013

At the moment im trying out with pointing to an array of functions. I got this working as following:

typedef void (* functionPtr) ();  
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};    
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}    
void loop(){
         A=0;
         B=1;
         functions[A][b]();
}  

But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:

error: argument of type 'void (Basic::)()' does not match 'void (*)()'

View 2 Replies View Related

C/C++ :: Difference Between Return 0 And Return -1

Oct 17, 2013

difference between return 0 and return -1 .and exit(0) and exit(1)

View 1 Replies View Related

C++ :: How To Return Value From A Pointer

Apr 1, 2013

Here is what's up:

struct Square {int number, myClass* myclass};
int main() {
vector<myClass> classes;
myClass unrelated;
classes.push_back(unrelated);
Square newClass = {3, &classes.at(0)};
.
.
.

myClass is a class I have. Now, in the class, I have a function what_value and I need to get the classes.at(0) from the pointer to it in another function. But the problem is, how can I do it? I'm completely stumped, here's what I thought of:

newClass.*myclass.what_value();

And it I get an error from the compiler. Basically, how can I do this in another function with a pointer:

classes.at(0).what_value();

View 1 Replies View Related

C++ :: Use EOF And Carriage Return Together?

Jun 9, 2013

I'm going to write a program that takes string until end of file(eof). An condition must be considered and that is it must also terminate by a new line. For example when it's prompting me to enter a string if I press enter it must terminate and exit the program. How is it possible? I tried saving carriage return("") as a string then I compared it with the entered string but it didn't work.

View 5 Replies View Related

C++ :: More Than 1 Return Value Per Sub Program?

Nov 11, 2014

Is it possible to have more than 1 return value from a subprogram?

View 5 Replies View Related

C++ :: Function Will Not Return Value

Jan 14, 2015

Why my function will not return this int. It does make it into the if(... prints "test 32" but will not return the given value(123456789).

#include <iostream>
using namespace std;
int lastZero(int x[]);
int main(){
int myArray[] = {1,1,1};
lastZero(myArray);

[Code] ...

View 4 Replies View Related

C/C++ :: Why Write Return 0 At The End

Jan 22, 2013

#include <iostream.h>
#include <conio.h>
int main ()
{
cout << "Hello World";
getch();
return 0;
}  

In the above code, why is it necessary to write getch() and return 0? What is their purpose?

View 7 Replies View Related

C++ :: How To Return Another Object Value

Nov 8, 2014

How can I return other object's value in a function(see code and comments)?

Person.h

Code:
#include <iostream>
#include <string>
using namespace std;
class Person{
public:
Person();
Person(string pname, int page);

[Code] ....

View 14 Replies View Related

C++ :: Return A Node Using Recursion

Mar 27, 2013

So the task is to find the node with minimum value of a binary tree (not binary search tree). the input is the pointer to the root of the tree. and i cannot make recursion work when i do if conditions. here is what i have Code: ​/*function 3-takses as input the pointer to the root of the tree and returns a pointer to the node with the minimum value*/

CPPtr minimumvalue(CPPtr SP){
CPPtr min = NULL; //node of minimum value
if(SP== NULL){ // if there is a node, begin comparing
return NULL;
}
else{
if(SP->data<SP->left->data){ //if the node has smaller value than its left child
min = SP; //update node of minimum value

[code].....

no matter where i call my function i get errors like unhandled exception at some memory. how to use recursion in this?

View 6 Replies View Related

C++ :: Return Value For A Type Class?

Apr 25, 2014

Code:
returnType operatorOperatorSymbol (parameterList); // syntax for operator overloading
Class Fraction

public:
Fraction operator-(const Fraction& f1){
Fraction r;
return r;
}

Is this even syntactically correct? It gives me errors. Im just trying to compile it without errors. I think the function makes sense since its returning a type Class

View 2 Replies View Related

C++ :: Best Way To Return Values From A Function?

Jan 24, 2014

I wanted to return a string I can do

Code:

string parseFilename(string fileName){
return fileName.subtr(/*blah*/);
}

Can I also use pointers/references here though? When would you use a pointer and when just a return statement?

View 2 Replies View Related

C :: Function Return Code / Value?

Sep 27, 2014

I have a function that needs to return a "uint8_t" value. However before doing the processing I need to perform a test on the argument to check if it's between expected boundaries. Although this function works it gives (a logical) warning that not always a value is returned although expected. What is the normal way for functions like these where I normally should return e.g. -1 in case the test doesn't succeed and otherwise the uint8_t (t) value?

Code:
uint8_t myFunc(int a) {
if (a >= 0 && a <= 100) {
// Perform actions
uint8_t = ...
return t;
}
}

View 9 Replies View Related

C :: How To Return Two Values With A Pointer

Mar 6, 2015

Here is the part of my code that I need to return two values. I am working on a roulette program and I need to return the choice and the number they are betting on. How can I use a pointer to achieve this?

Code:
int makeBet(char choice, int num){

printf("
What type of bet would you like to place? ");
printf("
Type n for number.
Type e for even/odd.
Type d for dozen.

[Code] ....

View 2 Replies View Related

C :: Void And Return Statement

Jan 11, 2014

If i declare a function as a void function. But for testing purpose if i use a return statement in the function definition. i have tested and found that the function does not return and executes the entire function. How does the function not return even if a return statement is available? Does the compiler removes this return statement or how it is?

View 2 Replies View Related

C :: How To Return As A Pointer To A String

Aug 1, 2014

How to return as a pointer to a string?

View 5 Replies View Related







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