0

Appreciate a quick response! - Chris

Not Yet Answered # Is it possible to pass back both a return variable & reference variable in one funct?

Ancient Dragon 5,243 Discussion Starter GPXtC02 Ancient Dragon 5,243 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

Appreciate a quick response! - Chris

0

>>is it possible to pass two variables back from a float function.. one through 'return variable' & the other through reference

Absolutely yes. If you can't get it to work right then post the code. Here is a common way to do it.

```
int foo( int& x)
{
x = 123;
return 1;
}
int main()
{
int n = 0;
int k = foo(n);
cout << "n = " << n << " k = " << k << "\n";
return 0;
}
```

0

```
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
float GetHS(float[], int, int&); //Proto-type.
float GetLS(float[], int, int&); //Proto-type.
// /////// //
float GetHS(float(Scores)[], int nRecords, int& indexa) { //Function computes the h
float Highest=Scores[indexa];
for(int a1=0; a1!=(nRecords+1); a1++)
if(Highest<Scores[a1])
{
Highest=Scores[a1];
indexa=a1;
}
return Highest;
}
// /////// //
float GetLS(float(Scores)[], int nRecords, int& indexb) { //Function computes the l
float Lowest=Scores[indexb];
for(int a2=0; a2!=(nRecords+1); a2++)
if(Lowest>Scores[a2])
{
Lowest=Scores[a2];
indexb=indexb+a2;
}
return Lowest;
}
// //////////////////////////////// //
void main(void) {
int IDs[50];
float Scores[50];
int i=0, argOne=0, argTwo=0;
GetData(IDs, Scores, i);
int nRecords=i;
cout<<"The highest test score was "<<GetHS(Scores, nRecords, argOne)<<" by "<<IDs[argOne]<<"."<<endl;
cout<<"The lowest test score was "<<GetLS(Scores, nRecords, argTwo)<<" by "<<IDs[argTwo]<<"."<<endl;
cout<<"The average test score for the class is "<<GetAverage(Scores, nRecords)<<"."<<endl;
}
```

As the problem revolves the data i'm getting back from the GetLS & GetHS functions i took out the functions that are irrelevant to the problem i'm having but left enough to give a good idea of what i'm after. Problem is after going into GetLS or GetHS (both are similar.. one to find the highestscore & the other the lowest score) The score part comes out with the data declared in argOne&argTwo (0). i.e it never changed. when i put in a 'cout<<indexa' or '*b' too make sure it is finding the right data it tells me I am as it prints out the data i want.. problem is it never returns the index part (argOne & Two) which is what i want.

"<<GetLS(Scores, nRecords, argTwo)<<" the right data fine (using the 'return variable'

but "IDs[argTwo]" doesn't return the correct value.

Thanks

0

in GetHS(), line 10, I assume **nRecords** is the number of valid entries in the array **Scores**. If that is true then line 12 is incorrect. Should be this: `for(int a1=0; a1 < nRecords; a1++)`

because arrays are numbered from 0 up to but not including nRecords. Same is true of line 24.

lint 28: indexb=indexb+a2; << wrong. should be `indexb = a2;`

lines 43, 44 and 45. Split those lines up something like below and see if that solves the problem, after correcting the above problems.

```
float x = GetHS(Scores, nRecords, argOne);
cout<<"The highest test score was "<<x<<" by "<<IDs[argOne]<<"."<<endl;
```

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...