C++ :: Using A Void Function For Data Input?
Feb 20, 2014
Modifying this program to Create a function that has the following prototype: void getInputChar(string, char &);.
The function should display the string on the screen and then use cin to read a char from the keyboard.
#include <iostream>
using namespace std;
bool ignoreCaseCompare (char, char);
[Code].....
View 1 Replies
ADVERTISEMENT
Mar 11, 2013
I am new to C++ ... My question is if I were to pass some data or values from the main() function through a void function (which main purpose is to display the data in a certain manner); how should one go about doing so?
For instance:
Code:
// example.cpp -- poorly written, just trying to learn
#include <iostream>
void format() {
using namespace std;
cout << "Time: " << min << hrs << endl;
[Code] .....
Obviously this is really poorly written, and confusing for the user. My main goal is to learn how to pass through values to a void function.
Also a bit off-topic, but is there a downside to place "using namespace std;" outside a function say if out of 100 functions only 10 of them use it? Would it make the program slower/unstable in any way or is this something one could do without any downsides?
View 3 Replies
View Related
Jan 15, 2013
I have a set of functions at work which are incredibly useful, however it only supports labels that come from a specific database because that database contains information on the type. I'd like to re-create it to make it more applicable to any member/static/global variables but don't know how to store the type.
I've already re-written it to an extent, but it only accepts int types. I'd like to template it to accept any type. The trick is storing that type so that the pointer can be dereferenced at a later time which I don't know how to do.
Interface:
typedef int T; // The goal is to remove this line!
namespace TimerDelay {
void SetAfterDelay ( T* lpLabelAddress, float delay, T target = T(1)); // Queues the set
void ManageDelays ( float dt ); // sets the labels when appropriate
}
Source:
#include <vector>
namespace TimerDelay{
struct DelayObject {
void* address; // I will probably need to add a container
void* target; // to hold the type, but how can this be done?
[code]....
Edit:Is it possible to store a std::iterator_traits<> struct as a member of my structure? The g_list isn't templated as it needs to accept all types at the same time. That means that DelayObject cannot be templated. I think that means that I cannot use a templated member class as the size may be inconsistant.
View 2 Replies
View Related
Feb 12, 2014
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.
View 6 Replies
View Related
Mar 24, 2014
I was reading about void as function argument, but I did not fully understand it's meaning in C.
In C++
void foo(void) {}
and
void foo() {}
are the same. It means no arguments for foo function. But in C it's different. First function means the same as in C++, but second means
In C, an empty parameter list means that the number and type of the function arguments are unknown. But if it is unknown you can't use this arguments if user specifies same. Because here are no variables to store them. So doesn't result are the some? You do not get any arguments. O do I can get this arguments from some hidden variable?
For example.
void foo() {
printf("%d", var);
}
foo(5);
It is very unclear for me. Do this apply to main function too?
int main(void)
int main()
or can I use arguments given to int main() like given to int main(int argc, char* argv[])
View 4 Replies
View Related
Jan 14, 2015
I need this break in my main function, but I'm not allowed to put it in void since void is not located in a loop. How can I solve this?
Code:
#include <iostream>#include <string>
using namespace std;
void login(string x, string y);
string username;
string password;
string x;
string y;
[Code] ....
View 6 Replies
View Related
Jan 20, 2015
I wanted to make a multiplication table.
Here's the code:
#include<iostream>
#include<conio.h>
using namespace std;
void initArray(int arg1[50][50], int r, int c) {
int val=1;
for(int row=0; row<r; row++) {
[code]....
I want the output to be like this:
1 2 3
2 4 6
3 6 9
If the user inputs 3 rows and 3 columns.
View 5 Replies
View Related
May 14, 2014
As part of my ongoing c programming education, I have written a program to use void pointers in a function,
Code:
#include <stdio.h>
#define MAX_NUMBERS 10
size_t size(void *object);
int main(void) {
}
[code]....
Now I think that the result 4 is the size of the pointer, so I'm confussed as why it doesn't give me the same result as 40.
View 2 Replies
View Related
Nov 2, 2013
I've been trying to get my program to call void functions with an if statement, but when i run my program and try to call one of the functions "worst case, best case, or random case" it doesn't get called. It just prompts the original menu.
#include<iostream>
#include<fstream>
using namespace std;
void bubbleSort();
void selectionSort();
[Code] .....
View 1 Replies
View Related
Dec 9, 2014
The purpose of this code is to calculate a pagecheck for intered hours and overtime for any hours over 40! This is what I have so far!
#include<iostream>
using namespace std;
void Amount (int hours, int wage, int sum);
void printCheck(int sum);
int main()
[code]....
View 1 Replies
View Related
Feb 26, 2013
how do you open a file inside of a void function
this is the code i have
#include <iostream>
#include <fstream>
#include <sstream>
[Code]....
View 6 Replies
View Related
Jun 1, 2013
How to pass the char something[8][8] for example to function void ( char pass.....)???
View 7 Replies
View Related
Oct 20, 2013
How can I pass a function as a parameter? I have a class that I'm trying to reuse and one of the methods in this class need to take three parameters, two ints and a function. In other words I want to be able to call a custom function every time this method is invoked when used in other classes. The function I want to call will not return any values, its a void function.
In my Class:
void Utility::someFunction(int var1, int var2, void customFunction) {
int num1 = var1;
int num2 = var2;
[Code] .....
View 9 Replies
View Related
Aug 31, 2014
I'm having issues with pointers and relationship operators in C.
I need to find a max and min value in a void function using pointers. max and min would work if they had values. mul works, because you can just do math operations with pointers.
There are 0 errors and warnings; but max and min are never going to work as is.
Clearly I'm missing something.
#include <stdio.h>
#include <stdlib.h>
void max(int *a, int *b, int *c, int *d, int *result);
void min(int *a, int *b, int *c, int *d, int *result);
void mul(int *a, int *b, int *c, int *d, int *result);
int main()
[Code]...
Your job will be to create a program that uses pointers. Your output must be done in the main function and the calculations MUST be done in the three functions. Therefore you MUST use pointers correctly.
You must declare and implement the following 3 functions. Below are the three prototypes that you must use in this program.
void max(int *a, int *b, int *c, int *d, int *result);
void min(int *a, int *b, int *c, int *d, int *result);
void mul(int *a, int *b, int *c, int *d, int *result);
The functions have the following meaning:
max
finds the max value of a,b,c,d and stores the largest value in result.
min
finds the min value of a,b,c,d and stores the largest value in result.
mul
multiplies a * b * c and divides by d. Stores that value in result.
Below is an example input/output. This input will be read in via the keyboard (use scanf).
input
output (note that user input is shown in bold)
1 2 3 4
Enter the 4 numbers: 1 2 3 4
The max is 4. The min is 1. (a * b * c) / d = 1
100 3 201 103
Enter the 4 numbers: 100 3 201 103
The max is 201. The min is 3. (a * b * c) / d = 585
Your output MUST match exactly the output below for the input from above. Your program must compile, failure to do so will result in 0 points. */
View 9 Replies
View Related
Jun 11, 2014
Why does the following code compile and execute without any error? I mean, the function compareid should get 2 arguments so why does the compiler not complaining, is it because of the type of arguments?
Code:
#include <stdio.h>
int compareid(void* info, int value); // ansi declaration
int compareid(void* info, int value)
[Code] .....
View 5 Replies
View Related
Jun 4, 2013
I have written a C++ program I have multiple of CSV file used as input, which I open one at a time and close it after extracting data to a output file which is the only file.
I run getline(inFile,line);
outFile << line << endl;
I run this code, and only part of it is goes to the output file I got, also have spacing randomly to specific file and inconsistent
But when I slower the code, like system("Pause") in the loop, I can get extract what I want perfectly....
Is my program running to fast, why getline would be skipping part of what things I want?
View 11 Replies
View Related
Jun 29, 2013
I have the following void function devised to assign "+1" or "-1" to each element of a matrix at random. While the function does what I want, when I print the values of the matrix all are set to zero:
#include <vector>
#include "aRand.h"
#include <iostream>
void initConfig(std::vector<std::vector<int> > premat, int nL, int nN) {
int * pnRand;
pnRand = 0;
[Code]...
The function pnRand_plus returns a pointer to an array of random numbers from 1 to 100, with seed time(NULL) + i. The values printed in main are zero, despite the values printed during the function run are fine (-1s and +1s).
View 2 Replies
View Related
Sep 1, 2013
//Point.cpp
#include "Point.h"
#include <iostream>
#include <cmath>
using namespace std;
Point::Point() { //Initialise the point to the origin.
[Code] ....
void Triangle::print() { //print out the Triangle with the format "( (x1, y1), (x2, y2), (x3, y3) )"
How do I accomplish this? When i test with cout << _point1.print(), there's an error:
[Error] no match for 'operator<<' in 'std::cout << ((Triangle*)this)->Triangle::_point1.Point::print()'
View 4 Replies
View Related
Jun 16, 2014
I made a basic console calculator in C++ using the Code::Blocks IDE and using the GNU GCC compiler. The problem in my code is my void function called 'operate' is getting ignored by not showing up in the console. After the first if statement I added a user input by saying Y for yes or N for no. Another if statement inside the first one shows if you type either 'Y' or 'y' it will execute the 'operate' function which will restart the calculator by having the same selection menu as in the int main function. When I call the function it does not show up in the console but just ends the program.
Here is my code:
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int input,input2, numAdd, numAdd2, numSub, numSub2, numMult, numMult2, numDiv, numDiv2;
void operate() {
cout << "Select a operator." << endl;
[code].....
View 2 Replies
View Related
Apr 25, 2013
I keep getting 'warning: control reaches end of non-void function' with this code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section ==0) {
return [comparativeList count];
}
if (section==1) {
return [generalList count];
}
if (section==2) {
return [contactList count];
How can I get rid of this warning?
View 3 Replies
View Related
Feb 12, 2013
So I am writing this code that analyzes a file called "analysis.txt" and prints out in an ouput file (called "report.txt") the results of the analysis, i.e.,(the frequency of all alphabet letters present in the file).
I am having trouble with outputing on the file2.
here is what I have:
Code:
#include<iostream>
#include<fstream>
using namespace std;
ifstream file1;
[Code]....
I tried to lose the "<<" after the file 2, but it's still giving me an error. how to output a void function on a text file?
View 14 Replies
View Related
Nov 10, 2014
I have a .txt file that I need to input into two parallel arrays. The first array needs to be on dimension and the second needs to be two dimensions.
This is a sample from the .txt file:
Australia62.762.163.359.7
Austria052.853.154.6
Belgium30.430.327.525.3
Canada61.356.257.754.5
Chile026.425.431.1
CzechRepublic038.327.325.2
Denmark65.067.162.355.0
Estonia51.732.929.834.3
Finland55.242.942.143.3
France35.728.330.228.8
Germany56.447.242.646.6
Greece30.326.925.013.1
Hungary032.521.818.6
Iceland068.271.666.0
this is what I have for code so far:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SIZE = 40;
const int COLUMN = 5;
void getData(ifstream& inf, string n[], double tstData[][COLUMN], int count);
[Code] .....
when I compile and run the code and have it display it does not read the first item into the 1-d array, instead it appears to read the 4th number from the left into the 1-d array and then into the second spot in the 2-d array, then again in its proper place and finally it has this number repeating through the rest of the arrays:
-92559631349317830000000000000000000000000000000000000000000.00 followed by the number 59.7 from the .txt and the long number again.
View 10 Replies
View Related
Mar 17, 2013
i need to return a struct pointer dynamically allocated inside a function call void function() which is done using 'out parameters' in following code
struct my_struct {
int x;
} void my_function( my_struct** result ) {
my_struct* x = new my_struct{ 10 };
//...
*result = x;
}
Now i have a doubt, so if i want to print the return value from struct pointer, should i need to print it in the void function() or in the caller the function...
View 3 Replies
View Related
May 18, 2013
This is a program I developed in which we had to define a class named BOOK with the data members and member functions as shown in the program..We have to:
(i) Make the user enter the values in the array BOOK.
(ii) Display the details that the user entered.
(iii) Search for a book from the array upon its Bno and display its details.
(iv) Search for a book from the array upon its Bname and display its details.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class BOOK {
private:
int Bno;
char Bname[20];
[Code] .....
But while running it the compiler gives the errors as:
Line 43 to 48: Illegal character '' (0x5c)
Line 69: Undefined symbol 'Display'
Line 88: 'BOOK::Bno' is not accessible.
Line 89:'BOOK::Bname' is not accessible.
Line 90:'BOOK::Author' is not accesible.
Line 91:'BOOK::Price' is not accesible.
Line 108:'BOOK::Bno' is not accessible.
Line 109:'BOOK::Bname' is not accessible.
Line 110:'BOOK::Author' is not accesible.
Line 111:'BOOK::Price' is not accesible.
from 43 to 48..the line feed was also used at many other places but there it was not given as an error so why here?
Line 69: I defined the Display() function outside the class since it contained control structures, so what's the error then?
About the lines the rest of the error( the "not accessible" ones) I know these data members are not accessible because they are in private visibility mode. But then how to make them accessible? (Without putting them in public because it was a part of the question to create the data members in private).
View 1 Replies
View Related
Dec 23, 2012
I know how to use functions pointers in C and C++ and I know if you have something like
char buf[] = {
0x48, 0xb8, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x48, 0xbf, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0x05
};
((void (*) (void))buf)();
That this will execute those binary instructions in hexadecimal notation BUT WHY? I don't get why that works since that's an array of data not a function?
View 7 Replies
View Related
May 6, 2014
I declared all functions in header file, such as:
bool readCase();
bool meshing();
bool readMesh();
bool calculateFlowfield();
bool readFlowfield();
bool calculateEvaporation();
And then I define them in separated .cpp files, each .cpp file include the header, but I got multiple definition error, why?
Even the int main() function, which only decalred and defined once got this error, why?
View 14 Replies
View Related