I am having problems with my function definition of a function that should return a structure value.
This is the error I get compute.cpp(9): error C2146: syntax error : missing ';' before identifier 's_advertisebus'
The error is on the line where I start my function definition typing my function type as a structure. A long time ago in c the keyword struct is used with the structure type like struct s_advertisebus s_readadbus(). I tried it both ways but I got errors.
// struct.h #ifndef STRUCT_H #define STRUCT_H
struct s_advertisebus { int nnumberofads; float fpercentused;
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?
#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?
I planned to build a four function fraction calculator adding some advance feature like error checking in input so that user are prompted to input correct numbers and operator.
I created a separate member function getOper() function for getting correct operator and getFrac() function for getting correct fraction.
My intention was just to get correct operator from getOper() function and returning the operator to switch in main() function to do specific calculation. But, i don't know why i am getting repeatedly error when inputting correct operator while debugging program.
Here's my complete code.
Code: #include <iostream> using namespace std; char c; class fraction { private : int num;
[Code] .....
I checked the program again by assigning char to variable "oper" and function "getOper(). But, result is same.And again i changed variable "oper" to default keyword operator, but, it really didn't worked as expected.
Ive been getting an odd error with this code when I try to compile it, as well as Im not quite sure as how to return my variable "compType" as a char type.
Main #include <iostream> #include "Shape.h" #include <iomanip> #include <cmath>
My code is supposed to read a five to four digit code of a resistor from a file and determine the resistor's nominal, lower and upper tolerance values. I have inputted my file's first resistor code as a string so I could run tests on it but the problem that occurs is that a get the wrong values from my switch-case statements. I have put printfs after the function call to see what the values were and they turned out wrong. If I could get my return values to be right then I could be on my way coding.
#include<stdlib.h> #include<stdio.h> double bandNum(char x); // function prototype that will read the resistor value for the first, second and possibly third band double bandMult(char x); // function prototype that multiplies the resistor by some value of 10 double bandTol(char x); // function prototype that the tolerance of the resistor is multiplied by
i cant seem to get the program to return the right grade it keeps returning 0 or 1. i want the program to return true for grades grades greater then or equal to 70 but cant find the right formula to put in the bool(). what formula should i put?
I am writing a class Player which has several char arrays as private fields. I am trying to write a method which returns an array as a pointer, but doesn't alter the array in any way, thus the const.
Here is a snippet:
Code: class Player { private: char state[MAX_STATE_CHAR + ONE_VALUE]; int rating; char last[MAX_NAME_CHAR + ONE_VALUE]; char first[MAX_NAME_CHAR + ONE_VALUE]; int groupNumber = NEG_ONE; public: char * GetFirst() const { return first; }
Visual studio is saying that the return type doesn't match.
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?
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;
I am making a game commonly know as the Hangman using C++.
Now I am trying to add a man in it like this:
0 |/ | /
Now the problem i am facing is that i am using a check that if a function returns the value 0 "return 0" it means the guess is wrong and it will not update the man but if it returns any value there will be a function called which will update the man.
I just wanna know that how i am going to use the check, the kind of thing that i am trying to use is, in general words "if(function returns a value) then update the man"
int main() { return match; }
How are we going to use it in check that if int main is returning 'match' in the check...
This simple little program is not returning a value. The output is
" (string) contains characters" (The number of characters is supposed to display between the 'contains' and 'characters.'
However, if I go to the function and cout the length, the cout in the main body displays just fine.
Here's the main portion :
cout << "'" << input << "' contains "; //Output of character count. charCount(input); cout << " characters, including any spaces. "; //Output of character count.
and here's the function.
int charCount(char *string) { int length = 0; //Variable to hold the number of characters. //Gets the number of characters contained in *string and puts that number into length.
As the title says, i'm using a function which returns a pointer to a struct:
the struct is the following:
Code: typedef struct POINT { uint16_t x; uint16_t y; }
Coordinate; the function i'm using:
Code: Coordinate * Read_XTP2046(void) {static Coordinate screen; //calculations to determine the coordinates screen.x=(temp[1]+temp[2])/2; screen.y=(temp[0]+temp[2])/2; // and so on... return &screen;}
The question is: how do i catch this pointer and make it into a Coordinate struct in which i can read the x and y.
In my main program i would do the following:
Code: Coordinate cor; cor = Read_XTP2046();
This does not work, as the function returns a pointer, but how to transform this pointer into a Coordinate struct.
I need to create a function which will print a list from 100Hz to 1000Hz then 1000Hz to 9000Hz. I have created a function in order to calculate and set up the frequency values from 100Hz to 9000Hz using two for loops as shown below. However I am unsure how to return this to the array at the main.
int main(void) { double Frequency[18]; system ("PAUSE"); return(0); } double Frequency (void) { int count;
I am using two threads and i want to take value of a function from one thread and use it in other. I am not good at the concepts of threads. Here is the following code:
Code: void ThreadA(void const *argument){ uint32_t status = I2S002_FAIL;
status = I2S002_Config(&I2S002_Handle0, &I2SConfig_U0C1_A); if (status != DAVEApp_SUCCESS) {
[Code] ....
So, i want to use the return value of temp_buffer from ThreadB into Thread C and want to put this value to TXBuf in ThreadA...
why the function is not returning the integer 1 or 0 ... We have two arrays A and B, each of 10 integers. Write a function that tests if every element of array A is equal to its corresponding element in array B. The function is to return true (1) if all elements are equal and false (0) if at least one element is not equal.*/
#include <stdio.h> #include <iostream> #include <time.h> using namespace std; int TEST (int arrayA[], int arrayB[], int j); int main() { srand (time(NULL));
Polygon* create_square(const Vector2d& position, const RGB& colour, const std::string name) { // Polygon, Vector2D, RPG and Vertex2d are structs with public data members only Polygon *temp = new Polygon; temp->name = name; temp->colour = colour; temp->position = position; temp->vertices = new Vertex2d; return temp; }
I have a function, which has to return some int data. In that function there are multiple return statements. There is also possibility that function may return in some cases. Will this result in undefined behavior???
I am writing a function to take two vectors and put them end to end in a third vector. I'm new to working with vectors, and I cannot figure out why my append function is not returning vector C. I had the function print out vector C within it to make sure the logic in the function wasn't the problem, and it worked perfectly. My code is as follows:
#include <iostream> #include <vector> using namespace std; //append function to put vector b after vector a in vector c vector <int> append(vector <int> a, vector <int> B)/>/>/> { vector <int> c;
[code]....
and my output is as follows:
Vector A contains: 10 18 123 172 Vector B contains: 283 117 17
The two vectors back to back are:
Obviously, the third vector is not returning from the function to main properly, but why.