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
ADVERTISEMENT
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
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
Nov 12, 2013
I am trying to create a program that reads my file filled with random words, it then compares the words after they are put into a 2d array and sees if there is any matching words.. unfortunately the count is not working for me (in function2 and function3) and I am not sure why..
Code:
#include<stdio.h>
#include<string.h>
char function1(char words_array[][17]);
int function2(char words_array[][17]);
void function3(int pairs, char words_array[][17]);
int main( void )
{ char words_array[20][17];
int x = 0;
[Code]...
View 6 Replies
View Related
Dec 14, 2014
I am writing a code that creates a deck of cards using a doubly linked list. One function, newDeck(), is made to create a new deck if the user wants. I don't have any problems creating the deck and it all seems to work fine, but when I run the whole program and a separate function needs to utilize the nodes in my deck, I get an error. Trying to find where there was a problem, I tried displaying the values of a card node in random parts of my code. At the end of the newDeck function, after the whole deck has been created, the card still displays correctly, yet when I return back to main immediately after newDeck has been called, I noticed that the values of my cards changed to either random values or they became null. I found this strange because in between the end of my newDeck function and at this point, there is no extra code so it doesn't seem as if there is any way the pointers could have been changed. Maybe It's because I don't have a complete understanding of pointers yet but is there any way that pointers can change values when returning from a function to main?
newDeck(head, tail, n); //this is how I call the function from main.
void newDeck(Card* head, Card* tail, Card* n) //this is my function body
{
for (int i = 0; i < 4; i++)
{
[Code]....
View 2 Replies
View Related
Mar 8, 2014
I have a class where a method based on the type passed I should return a value.
prototype declared in the header file:
template <typename T>int getNum() const;
Code of the cpp file:
template <typename T> int class::getNum() const{
int c = 0;
for(int i=0;i<v.size();i++)
if(typeid(*(Pro*)v.at(i)) == typeid(T)) c++;
return c;
}
To invoke the method as I do:
ostream & operator << (ostream & os, Pro & obj) {
return os << obj.getNum();
}
View 4 Replies
View Related
Dec 4, 2014
I missed last class on doing void functions because I got sick and im completely lost! ive being using the texts book example for a reference but its not running !
The output should look similar to this:
how much was your shirt?
20
shirt 20.00
tax =1.20
the total 21.20
Code:
include <iostream>
#include <iomanip>
using namespace std;
void getShirtCost(double shirtCost);
void calculate(double shirtCost,double taxAmount, double total, double taxamount) ;
void printReceipt(double shirtCost, double taxAmount, double total, double taxamount);
[Code] ....
View 1 Replies
View Related
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
Jul 14, 2014
I'm beginners in C Programming, i have a question about Structure in C. i know in Function it is possible for
1. Sending the value of argument
2. Sending the address of the argument
3. Returning values from a function by return statement
Does in Structure it is possible for
1. returning structure from a function using by return statement
View 2 Replies
View Related
Mar 22, 2013
I am posting this simplified piece of code that is a bit confusing for me. There are two functions that I call. One shows the expected results but the result of the other one rather puzzles me.
//#define defineVecTyp Vec3f
#define defineVecTyp float
template <typename vecTyp>
vecTyp buildLaplacianPyramid(cv::Mat inputmat) {
vecTyp lapPyr;
[Code].....
Calling the function sum1 does not change the values stored in the variables val1 and val2. The output of the program is as follows:
val1= 1 ## val2= 10 // before the call of function sum1
val1= 1 ## val2= 10 // after the call of function sum1
sumOfVals= 22
This is quite obvious and as expected and I just pasted this piece of code as an example for better clarification.
However, if I call the function buildLaplacianPyramid and apply a function for Gaussian Blurring, this also effects the cv::Mat passed to the function. The line imshow("M1, after buildLaplacianPyramid",M1); therefore shows an image that is blurred. Since I am not passing a pointer to the cv::Mat I do not understand why this should be happening. I was assuming that there would be a copy of the cv::Mat M1 to be used within the function. Therefore I was expecting the cv::Mat M1 to retain its original value. I was expecting that all changes applied to cv::Mat inputmat within the function would not have any influence on the cv::Mat M1. Just like in my other example with the sum.
View 3 Replies
View Related
Nov 22, 2014
The switch statement is giving me trouble. Worked fine in the main, but when I had to put it in separate functions per my professor, I had several issues. I guessing I am not calling the function correctly. Our group worked on it but could not find a solution to fix the switch statement.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <conio.h>
using namespace std;
//function prototypes
int menu(); //function to show main menu
void Seating_Chart(); //function to show seating chart
[Code] ....
View 2 Replies
View Related
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
View Related
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
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
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
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
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
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
Feb 1, 2015
I am currently just trying to update a record in a SQL database.I can add a record and delete a record just fine but when I go to update I get no errors but it just doesn't update.
Here is what I have and done coding for hours trial and error
private void btnAddProd_Click(object sender, RoutedEventArgs e)
{//validate method // product = new Product(txtProductName.Text, Convert.ToDecimal(txtProductCost.Text), txtProductType.Text);
product = new Product();
MakeProduct(product);
if(modify) {
Product theOneAndOnly = new Product();
[Code] ....
View 1 Replies
View Related
Nov 9, 2014
The file name is "movie.dat" and currently i was able to save data into the file in this order:
[movie_code] [movie_dur] [movie_title] [movie_rating] [movie_dir] [movie_genre] [movie_status]
[12345] [120] [Movie] [PG13] [Director] [Comedy] [Active]
I want to search for the "movie_code" and change the [movie_status] from Active to Inactive.
So lets say for example i have a movie code 12345 saved in my movie file. I want to change the value from "Active" to "Inactive"for argument sake.
This is the code i was trying to do it with:
FILE *movie_fp;
movie_fp = fopen("movie.dat", "r+b");
int m_code;
MOVIE movie_data;
printf("*** Welcome to the movie updater! ***
");
if(movie_fp != NULL){
[Code] ...
View 2 Replies
View Related
Apr 27, 2013
I've just integrated the Windows SDK V7.0A into my VS2005 application, and I'm getting the dreaded "Application configuration error" when I try to run it on an XP machine.
It runs fine on the development machine, and some customer machines (Win7 and Win8), but will not run on XP due to missing/incorrect version dlls.
I've rebuilt all my libraries, but still no joy.
So, my first question is - If I upgrade the Windows SDK to V7.0A, do I also need to use MFC 10 and msvcrt10, or can I stick with MFC 8?
The next question is, how do I find out which dlls are missing, and which libraries or other dlls are requesting the missing versions?
View 11 Replies
View Related
Sep 7, 2013
How to make if else code below into SWITCH STATEMENT?
cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;
[Code]....
View 6 Replies
View Related
Dec 14, 2013
I am writing a program that manages a group of tool bins. This group is handled as an object that is an array of two element structures called InvBin. I initialize the bins with data from a file which contains the descriptions and initial quantities. I also have functions to add or subtract items from a bin and a function to display a report of the description and quantity of all of the bins.
The add and remove functions work correctly based on the cout statement in the functions, however when I display the report, it displays the initial quantity instead of the new quantity. In addition, when I use the add and remove functions again on the same bin, they use the initial quantity.
These are the add and remove functions and the report function from the main program.
Code:
//Adds an item to a bin
void addItem(HANDLE screen, BinManager tools, int &count) {
int binNum;
int addNum;
system("cls");
[Code].....
View 2 Replies
View Related
Jul 16, 2013
I am having trouble updating my global pointer in the following code,
Code:
#include <iostream>
using namespace std;
struct RB{
RB()=default;
RB(int clr):color(clr) { }
int color;
[Code] ....
The problem is, at line where I compar y==Tnil, It is evaluating to false at the first insert. But It should be true. again, after ending the function, T again becomes equal Tnil, as a result , none of the is being inserted.
View 2 Replies
View Related
Jul 18, 2013
Code:
#include<stdlib.h>#include<stdio.h>
#include<unistd.h>
#include<math.h>
int main(void)
{
double N, NG, LG, epsilon, root; // setting all variables to type double
[Code] .....
The goal is to create a program to calculate the square root of a number provided by the user to an error tolerance 0.005
Looking around i fond the Code: fabs(NG - LG) < epsilon); section that was very similar to what i was using, but if this is better im down for that.
My issue, from what i can see, is the updating of the values of LG. if the test for error tolerance fails then LG needs to take on the value of the results of NG.
Now I am not 100% that is the point of failure due to the fact the script does calculate the root properly, but it never exits the program once it reaches the tolerance level.
Code: imac:ENG-3211 user$ ./hw_4_1
Please enter the number you wish to find the square root: 4
4.00 2.500
4.00 2.050
4.00 2.001
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000
And it continues forever until i manually break the program even though the answer was found, in this example, on the 4th loop.
View 8 Replies
View Related
Mar 17, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define MAX 200
[Code] ....
Inside of my studentinfo.txt file
Code:
Jnh Has 2353325 23 56 72 34 67 22 46 42 5 23 56 23
Daniel Laurent 6744590 10 20 30 40 50 60 70 80 90 100 40 50
This code is working totally fine. Right now, I'm trying to update a specific data from the student info. Let's say I'm trying to update my student number of Daniel. So, in this case, I want to replace 6744590 to some other student number. I think I have to use fseek() or rewind() and use fputs() but, I don't know how I should decide where to look.
View 8 Replies
View Related