C++ :: Returning Multiple Variables In 1 Function To Main

Oct 22, 2013

I am trying to return 2 numbers from my function to main(). They are both read in from an input file but it is not working out.

#include <fstream>
#include <iostream>
using namespace std;
ofstream outfile;
void heading(int);
int stuid(int,int);

[Code] ....

View 4 Replies


ADVERTISEMENT

C++ :: Returning Char Array To Main Function

May 15, 2014

I want to return a char array to the main() function, but its returning garbage value.

#include<stdio.h>
//#include<conio.h>
#include<string.h>
char* strtrmm();
int main() {
char str1[100],c1[100];

[Code] .....

View 5 Replies View Related

C++ :: Returning Two Separate Variables In A Function?

Dec 12, 2013

How to use a function twice to calculate two different variables. How to have a function compute the city tax, then it uses the function a second time to compute the county tax.

My program compiles, and runs fine, however it only outputs the city tax calculation. It seems it never attempts to calculate the county tax.

One thing: All of the directives I used is what we are limited to, no more, no less. He requires a set format and will dock points of you use anything but those directives and void main().

Here is my code so far:

/* function for city tax calculation */

#include <iostream>
using namespace std;
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
const double city_tax_rate=0.03;

[Code] ....

I am using Visual studio 2010.

View 9 Replies View Related

C/C++ :: Main Function Can Only Declare Variables And Functions

Mar 9, 2015

I need making my main function to run while not having any if or for statements. It can only declare variables and functions. Since my main function has command line arguments, how to so.

// This program counts all the words in a given file.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
FILE* txtFile = NULL; // File Pointer
char str[1000000];

[Code] ....

View 5 Replies View Related

C :: Passing Int And Float Variables From Main And Getting Values From Another Function

Feb 3, 2015

I have the main() - which has entries like

Code:

main() {
int ss, ret, z;
float yy;
ret = function1(&yy, &ss, &z);
//int function1(flat *cc, int *dd, int *k) - is it correct?

[Code]...

View 5 Replies View Related

C++ :: How To Return Multiple Value From Function To Main

Feb 25, 2013

Get user input should be done in a function. The function should read the product number, price per unit, and quantity sold and return them to the main().

Display the value of product number, price per unit and quantyty sold in main().

View 7 Replies View Related

C :: How To Make Main Function Only Allowed To Declare Variables And Functions

Mar 6, 2015

So I need to make a main function have no if/for/etc. statements so I need to move it to another function and call it in main. The problem is that it's a command line argument function so I'm confused on how it works. Here's an example:

Code:

#include <stdio.h>
int main(int argc, char* argv[])
{
printf("The program name %s", argv[0]);
if (argc == 2) {
printf("Argument supplied is %s", argv[1]); }
else if (argc > 2) {
printf("Too many arguments");}
else {
printf("One argument");}
}

How can i make this into two functions with main only declaring variables and calling other functions?

View 2 Replies View Related

C++ :: How To Return Multiple Values To The Main Function

Oct 13, 2013

in a function how do you return multiple values to the main function.

View 4 Replies View Related

C++ :: Returning Values To Main

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

C :: Returning Value For Item To Variables?

Mar 4, 2014

What the code below is not doing is returning a value for item to my variables (item1, item2, etc..) I'm not sure how I can make a function prototype that will ask for input and basically recycle after going through the program to a new value for each item. I also need to input individual tax for each item. I will also post it in this message:

double tax, item,salesTax;
double cost(double);
double CalcSalesTax(double);
main(){
double total,item1, item2, item3, item4, item5, tax1, tax2, tax3,tax4,tax5;

[Code].....

View 13 Replies View Related

C++ :: Returning Variables As Char Type With If Statement

Feb 17, 2014

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>

using namespace std;
void inputShape( char shape)

[Code] ....

View 1 Replies View Related

C++ :: How To Access Member Variables From Main

Nov 10, 2013

my clsLocalStudent inherits from clsStudent. How to i set my accounts information (accountNumber, accountHolderID . . . . .)?

Code:
#include <iostream>
#include "clsInterest.h"
#include "clsDate.h"

[Code]......

View 3 Replies View Related

C++ :: Accessing Class Variables In Main

Apr 16, 2014

I am not able to access the class variable noof_vertex in the function merge , the error is the variable is private . below is the code :

#include <iostream>
#include <ctime>
#include <cstdlib>

[Code]....

View 1 Replies View Related

C++ :: Returning Multiple Values?

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

C++ :: Returning Values Or Using Pointers To Redefine Variables Passed As Arguments?

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

C :: Adding Constant To Multiple Variables

May 20, 2013

Instead of using:

Code:
x=x+k
y=y+k
z=z+k

Is there a more elegant method of adding the same constant to many variables?

Something like: Code: (x, y, z) = (x, y, z) + k ??

View 5 Replies View Related

C++ :: Global Variables For Multiple CPP Files

Jan 19, 2014

I am trying to get variables that are global to multiple files. I have mananged to make constant variables that are global but maybe not in the best way. In the header i have the constant variables being defined:

const int variable_Name = 5;

And the cpp file:

#include <iostream>
using namespace std;
#include "vars.h"
int main ( ) {
cout << variable_Name<< endl;
system ("pause");
return 0;
}

Is there a better way to do this and to make the variables able to be changed within the cpp files.

View 7 Replies View Related

C++ :: Bit-checking Across Multiple Classes Private Variables

Oct 6, 2013

I am writing a bit-check function just to make it easier on myself to check status flags in my classes. I use char variables and each bit represents something on or off. Since I have numerous classes that will use this functionality, it makes sense to write and compile the code only one time rather than for each class. I was thinking of writing the function and including it as a "friend" function to each class that needs it. Is that an appropriate way to do it?

View 2 Replies View Related

C/C++ :: How To Create A Table With Variables From Multiple Structs

Aug 1, 2012

I would like to create an array of struct variables inside a table to avoid using many if/else and/or switch/case statements. I have attached a simple example of what I am trying to do, it doesn't work. For the table "sTablePtr" I see different values than what I set, when I dereference it with a "&" it just shows me the addresses of the variables. However at the end, when I do print out the values, by just using the structs themselves, they print out the values correctly.

My structure declarations must remain a pointer. To be clear, what I am trying to do is have sTablePtr[i] show me the correct values I set, in this case I want the for loop to print out 1, 2 and 3. If there is a different way of doing this, I am open to it as long as I can use a table of my struct variables to avoid many if statements.

#define MAX_CNT 3  
typedef struct {
   int nNum;
   int nCnt;   
}sDummy1;  

[Code] ....

View 4 Replies View Related

C :: Read From And Store Values Of Each Line In Multiple Variables

May 6, 2013

So I have this text file that I am trying to read from and store the values of each line in multiple variables. Let's say my text file contains

AXSYZ3482 Tom 100 112 and my code below here works fine when the lines in the text file is separated by spaces.

Code:

while (fscanf(fp, "%s %s %d %d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

But let's say my file was to look like this instead.

AXSYZ3482:Tom:100:112

But if i try this below...

Code:

while (fscanf(fp, "%s:%s:%d:%d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.

So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth.

View 4 Replies View Related

C :: Socket Programming Support Multiple Ports - Defined Variables

Sep 3, 2013

I want to put my socket programming example of how it can support multiple ports. I want to make the process more requests from distributing particles to create non-blocking structure

ports support ports defined variable.

Code:
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "errno.h"
#include "string.h"
#include "sys/socket.h"

[Code] .....

View 2 Replies View Related

C++ :: Reading From File And Store Values Of Each Line In Multiple Variables

May 6, 2013

So I have this text file that I am trying to read from and store the values of each line in multiple variables.

Let's say my text file contains

AXSYZ3482 Tom 100 112

and my code below here works fine when the lines in the text file is separated by spaces.

while (fscanf(fp, "%s %s %d %d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

But let's say my file was to look like this instead.

AXSYZ3482:Tom:100:112

But if i try this below...

while (fscanf(fp, "%s:%s:%d:%d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.

So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth. How I can accomplish this?

View 2 Replies View Related

C++ :: Keyboard Function That Is Called In Main Function To Make Shape Move

Jan 19, 2013

Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.

void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {

[Code].....

But when I try to call it, trying to copy my previous method,

glutKeyboardFunc(Player1.playerControls);

I get an error

error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member

I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.

View 2 Replies View Related

C :: Main Function Does Not Return Any Values When Calling Other Function?

Jun 9, 2013

The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.

right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.

Code:

#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {

[Code].....

View 4 Replies View Related

C :: How To Pass Main Function Argument To Some Other Function

Dec 26, 2014

I am writing a program in which a Fucntion has to be wriiten to parse the Command Line . When I include Code for parsing in main fuction iteslf ,its run ok . But I want to make a fucntion of that code and call it from main ,than it show Segmentation error .

By using Debugging I found Some thing is mess with " -m" Parameter of Command line , But Cant Rectify it ..

Code:
int main (int argc, char *argv[]){
//get_parameter_value(argc,argv);
// buffer[packet_size+1]= char ("'");
while (argc > 1) {
if (argv[h][0] == '-')

[Code] .....

View 3 Replies View Related

C/C++ :: How To Get Formation From Pointer Function To Main Function

Feb 13, 2014

int example (int [], int, *int,*int,*int,*int);
int main () {
My code will be here
example (int array[], int size, &a,&b,&c,&d); // Like this??? I try it didnt work

[Code] ....

View 2 Replies View Related







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