Visual C++ :: GetMost And GetLeast Functions Returning Erroneous Values
Apr 5, 2014
After compiling, I cannot understand why my getMost and getLeast functions are returning erroneous values. I've done everything I could think of to try and fix this, Problem and code below.
A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a twodimensional 3 * 7 array, where each row represents a different monkey and each column represents a different day of the week. The program should rst have the user input the data for each monkey. Then it should create a report that includes the following information:
* Average amount of food eaten per day by the whole family of monkeys.
* The least amount of food eaten during the week by any one monkey.
* The greatest amount of food eaten during the week by any one monkey.
Input Validation: Do not accept negative numbers for pounds of food eaten.
Code:
#include <iostream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
// Constants.
const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;
[Code] ....
View 3 Replies
ADVERTISEMENT
Apr 9, 2014
I have an assignment in my C++ class that is to create a menu based coffee shop program. Here is what I have so far:
#include<iostream>
#include<cmath> //doubt this is needed but i added it just in case
using namespace std;
[Code]....
View 19 Replies
View Related
Apr 2, 2015
I'm working on what I thought was a pretty simple program. I'm writing a menu driven program that will allow users to obtain specified measurements of several geometric figures. I was trying to test each each time I add a function.
I keep getting this error. error C3861: 'AreaOfSquare': identifier not found.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
int menu() {
int choice;
[Code] ....
View 4 Replies
View Related
Jun 21, 2013
Passing and returning character and integer arrays with functions using simple programs...use pointers if necessary
View 1 Replies
View Related
Jul 13, 2013
I am currently doing a bodyfat calculator for a course in school.I'm having a problem getting an output returned from my while loop, which determines the user's gender by user input.My function (outside of main) is currently:
Code:
char gendercheck(gender){
while (true) {
gender = _getch();
if (gender == 'M' || gender == 'm') {
system("cls");
printf("Your selected gender is male.");
break ;
[code]....
My failed tries include "return gender" and "return genderpicked" statements in both the if-functions and the loop itself, which I have deleted since that didn't work. My goal is to get a character stored in gender, so that I can use the information of the user's gender in my main function from this point and onwards.
MY MAIN IS:
Code:
int main() {
char *genderpicked ;
char gender ;
genderpicked = &gender ;
[code]....
View 9 Replies
View Related
Nov 5, 2014
I am working on this program below. The problem I am having is trying to return totalDays to the main. In the numOfDays() function there is a for loop that adds the totalDays (totalDays = totalDays + days). I have just been getting errors in returning the correct amount of totalDays to the main from the numOfDays function.
#include <iostream>
using namespace std;
int numOfEmployees();
int numOfDays(int);
int main() {
int totalDays = 0;
[Code] ....
View 2 Replies
View Related
Oct 9, 2013
I would like to return multiple values from one function to access in different functions. For example:
int function1(//what goes here?)
{
int a ;
a = 1 + 2 ;
int b ;
b = 3 + 4 ;
return (what goes here if i want to return the value of a and/or b to use in another function?) ;
void function2()
{
//now i want to use the value of a here to use in an equation, how do i do that?
//now i want to use the value of b here to use in an equation, how do i do that?
}
View 4 Replies
View Related
Jul 23, 2013
So I have a function like the one below
bool get_array( float input_param, vector<int>& output_param ){
// some code that handles output_param output
if( error ) return false;
}
So basiclly this function must return 2 value well one of the value is just a bool returning whether the procedure doesn't fail at some point or not.
is there any better way to write this function ?
View 7 Replies
View Related
Apr 1, 2013
I have been trying to make a function that compares all the values of the array and if they are all equal will return a value to print true. The problem I am having is that regardless of what values I enter the function is always returning true. Any way to tell the program o check all the values in one command instead I put them each,
Code:
#include<stdio.h>
#include<stdlib.h>
int compare(int arrayA[], int arrayB[]);
[Code]....
View 2 Replies
View Related
Feb 25, 2015
I wrote this code for a homework assignment, everything runs fine but the function void percent_votes (line 66) isn't calculating properly, it outputs 0.00 for each value. I have tried everything I can think of to try and make it work.
Here is the assignment: Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election.
Here is the code I have written:
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
[Code].....
View 4 Replies
View Related
Mar 21, 2015
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
[Code] ....
View 5 Replies
View Related
Dec 2, 2013
When i return 0; at the function int userselect (int user, int comp)my output displays twice and when i ask the user to run it again the computers selection of rock, paper or scissors remains the same it doesn't find a new random number. So i made the function userselect return to main(). This works and my output is displayed once, but when i run it it skips my while part of my do while loop completely so it loops the program without asking the user if they wish to run it again.
but when i return main() the computers choice re-randomizes every time so i need to find a way to get the while part of my do while to initialize and the program to not loop without the option of ending it.
#include <iostream>
#include <string>
#include <cmath>
[Code]....
View 1 Replies
View Related
Feb 28, 2014
Which is more efficient in functions? Returning values or using pointers to redefine variables passed as arguments?
I mean either using:
void ptr_Func(int *x)
{
*x = *x+1
}
or
int ptr_Func(int x)
{
return x + 1;
}
In terms of speed, memory use etc.I want to know general efficiency, I know it will obviously vary with different uses and circumstances.
View 7 Replies
View Related
Oct 24, 2013
In my Header file:
class MyData {
struct Fparams {
int i;
bool flag;
};
}
Now in CPP file:
void MyData::GetData() {
Fparams fParam;
fparam = AllData();
[Code] ....
Now i get an error saying - error: no match for 'operator=' in fparam = AllData(); ........
View 10 Replies
View Related
Apr 23, 2013
I am trying to read data from a smartcard using scardTransmit. But the data read is always 6D 00 CC CC (Be it for name, expiry date or any other data, always the same.) This is probably some junk data?
My code would read as below :
Code:
#include "stdafx.h"
#include <winscard.h>
#include <stdio.h>
#pragma comment(lib, "winscard.lib")
bool transmitFunction(SCARDHANDLE hCard, LPCBYTE pbSend) {
bool rv = false;
int i =0;
[Code] ....
SCardEstablishContext and SCardConnect are successful.
Prints for pbRead in getCPRFirstNameEn() is : 6D 00 CC CC
Note : I have edited the above to include actual code.
I have also tried sending different APDU commands (for getting second name, expiry date etc) , but the print for all is the same.
View 14 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
Jul 29, 2013
I am trying to get some confirmation about how to pass to functions. If you want to assign default values to certain parameters, and have others defined inside the body of int main(), then the parameters which will have default values go at the end of the list. Is that correct?
i.e. The following code is wrong, because we cannot leave a black in the function call on the third line of the main function. However, if we switch the prototype to void Passing (int a, int c, int b = 1); and the function definition to void Passing (int a , int c, int b) everything will be okay and we can call the function as Passing (a, c).
In brief, we cannot do this EVER:
Passing( a, , c)right?
#include <iostream>
using namespace std;
[Code]......
View 4 Replies
View Related
Nov 5, 2014
I was given an assignment where I have to input two points (four integers) on a Cartesian plane from a file and then process it using functions. My professor is very particular so the comments are a bit excessive, but here's what I have.
double radiusFn(double, double, double, double);//4 double values, one for each point. All points are needed for the calculation of distance in this function.
double diameterFn(double);//Only uses one double value - the radius. Both functions below use the same value.
double circumferenceFn(double);
double areaFn(double);
int main() {
[code].....
The file reads:
Quote
1 2 3 4 5 6 7 8 9 10 11 12
View 2 Replies
View Related
Mar 22, 2013
Code:
#ifndef CANDIES_H
#define CANDIES_H
#include <iostream>
#include <fstream>
#include <Global.h>
class Candies
[Code]...
Code:
#include "Candies.h"
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <sstream>
[Code]...
When I tested it, the file name in getName() outputted the right file name. However the file name in loadName() does not print out anything in the console window.
I want it to be so that the strings in [I]name_addTXT.c_str() in both functions are equal.
View 4 Replies
View Related
Sep 5, 2014
What "int values" is supposed to mean as parameters to these functions? I'm not sure what do with them. Also how to input values into the array via functions. I was trying to but I just don't understand how to connect a user's input to a function to then enter into an array.
// input reads “values” integers from the user to place in the array data. It prompts the user for each value individually with the ordinal position of the value.
void input (int data [size], int values);
// Places the sum of corresponding values from arrays a and b and places the results in array s. The first “values” integers in the array are processed.
void do_sums (int a [size], int b [size], int s [size], int values);
[Code]...
View 2 Replies
View Related
Dec 29, 2012
Code:
struct NewPlayer {
int level;
int intelligence;
int damage;
};
int CharacterInfo(NewPlayer MageWizard, int Clevel,int Cint, int Cdam)
[Code] .....
View 1 Replies
View Related
Aug 23, 2013
This code is for fun, and have it doing a lot of what I want it to, just not all. I want random generated to write to a txt file. I tried to use an array but that failed. I wanted to use an array because i am only passing one value. Which makes sense since the random generated function is an int.
I made the fprintf as a comment but hopefully soon it will be able to send the values to the txt file. After that I will tackle the function.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define HIGH 49
#define LOW 1
int random_generated()
[Code]...
View 11 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
Feb 10, 2013
I have Mq4 platform calling functions from DLL some how it doesnt make any differents when I make the call....
// DLL Code
#define WIN32_LEAN_AND_MEAN
#define MT4_EXPFUNC __declspec(dllexport)
using namespace std;
std::string My_String;
#define stringify(mymonths ) # mymonths
[Code] ....
I call this function
bool counts = StartRulls(bars);
Print("counts =",counts );
2013.02.09 23:03:242010.03.31 16:37 My_Mq4.mq4 EURCAD,M5: counts = 1
My result always stays 1
View 4 Replies
View Related
Dec 9, 2012
I want to build a dll library with visual c++ 8.0 and got an "unresolved symbol" linker error message when trying to use the library with an application. So I checked the dll library with dependency walker for the exported functions, the needed functions were missing in the library.
I then dumped the corresponding object file with dumpbin.exe, the function was declared as public, like the other exported functions. On the next step, I set the verbose switch for link.exe.
The verbose log told me, that the function was discarded on the linker run. What can lead to that behaviour of the visual c++ linker ?
View 3 Replies
View Related
Aug 27, 2014
I write a DLL MyDLL.dll with Visual C++ 2008, as follows:
(1)MFC static linked
(2)Using multi-thread runtime library.
In the DLL, this is a global data m_Data shared by two export functions, as follows:
ULONGLONG WINAPI MyFun1(LPVOID *lpCallbackFun1) {
...
Write m_Data(using Critical section to protect)
[Code]....
Although MyThread1 and MyThread2 using critical section to protect the shared data m_Data, I will still suspend MyThread1 before accessing the shared data, to prevent any possible conflicts.
The problem is:
(1)When the first invoke of MyFun2, everything is OK, and the return value of MyFun2(that is nResult2) is 1 , which is expected.
(2)When the second, third and fourth invoke of MyFun2, the operations in MyFun2 are executed successfully, but the return value of MyFun2(that is nResult2) is a random value instead of the expected value 1. I try to using Debug to trace into MyFun2, and confirm that the last return statement is just return a value of 1, but the invoker will receive a random value instead of 1 when inspecting nResult2.
(3)After the fourth invoke of MyFun2 and return back to the next statement follow MyFun2, I will always get a "buffer overrun detected" error, whatever the next statement is.
I think this looks like a stack corruption, so try to make some tests:
1.I confirm the /GS (Stack security check) feature in the compiler is ON.
2.If MyFun2 is invoked after MyFun1 in MyThread1 is completed, then everything will be OK.
3.In debug mode, the codeline in MyFun2 that reads the shared data m_Data will not cause any errors or exceptions. Neither will the codeline in MyFun1 that writes the shared Data.
View 4 Replies
View Related