Click here to Skip to main content
16,012,468 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: preprocessor macro inside string literal? Pin
cmk30-Apr-07 14:17
cmk30-Apr-07 14:17 
GeneralRe: preprocessor macro inside string literal? Pin
PJ Arends1-May-07 5:20
professionalPJ Arends1-May-07 5:20 
GeneralRe: preprocessor macro inside string literal? Pin
cmk1-May-07 11:45
cmk1-May-07 11:45 
AnswerRe: preprocessor macro inside string literal? Pin
Stephen Hewitt30-Apr-07 17:44
Stephen Hewitt30-Apr-07 17:44 
GeneralRe: preprocessor macro inside string literal? Pin
PJ Arends1-May-07 5:21
professionalPJ Arends1-May-07 5:21 
QuestionC++ help for arrays...average a value Pin
wertyou29-Apr-07 17:00
wertyou29-Apr-07 17:00 
AnswerRe: C++ help for arrays...average a value Pin
PJ Arends29-Apr-07 17:15
professionalPJ Arends29-Apr-07 17:15 
GeneralRe: C++ help for arrays...average a value Pin
wertyou29-Apr-07 17:17
wertyou29-Apr-07 17:17 
Ok- here is the whole lab & the compiler errors are on line 127, which is the average_array. The total is defined in the sum part.


#include<iostream>
#include<string>
#include <iomanip> // For setw()
#include <fstream> // For file I/O
#include <cstdlib> // For the exit() function
using namespace std;
typedef int arrayType[]; // Declare data type alias
typedef char fileSpec[]; // Declare data type alias

// user defined function prototypes
void pause(void);
void load_array_from_file(fileSpec filename, arrayType nums, int arraySize);
void display_array(arrayType nums, int arraySize);
int sum_array(arrayType nums, int arraySize);
int average_array;

//******************************************************
// main
//******************************************************

int main(void)
{
//------------------------------------------------------
// Place the D6_Lab_01_Input.txt file on the root level
// of your C: (hard disk) drive
//------------------------------------------------------
char filename[] = "c:\\D6_Lab_01_Input.txt";
const int FARMERS = 7; // Input file has at least 7 members
int acres[FARMERS];

// call functions
load_array_from_file(filename, acres, FARMERS);
cout << "The individual farm acerages are: \n";
display_array(acres, FARMERS);
cout << "\n\nThe total acerage is: " << sum_array(acres, FARMERS);
cout << "\n\nThe average acerage is: " << average_array;
pause();

return 0;
}

//******************************************************
// pause
//******************************************************

void pause(void)
{
char pause;

cout << "\n\n\nHit Enter Key to Continue: ";
cin.get(pause);
cin.get(pause);

return;
}

//******************************************************
// load_array_from_file
//******************************************************

void load_array_from_file(fileSpec filename, arrayType nums, int arraySize)
{
ifstream inData; // Used to read the data from a file
int index; // Loop counter

inData.open(filename); //Open input file
if (!inData)
{
cout << "\n\nError opening data file: " << filename << "\n\n";
pause();
exit(EXIT_FAILURE);
}
else
{
for (index = 0; index < arraySize; index++) // Load the array
{
inData >> nums[index];
}
inData.close();
}
return;
}

//******************************************************
// display_array
//******************************************************

void display_array(arrayType nums, int arraySize)
{
int index; // Loop counter

cout << "\n*************************";
for (index = 0; index < arraySize; index++)
{
cout << "\nMemeber " << index+1 << " value is: " << setw(5) << nums[index];
}
cout << "\n*************************";
return;
}

//******************************************************
// sum_array
//******************************************************

int sum_array(arrayType nums, int arraySize)
{
int index; // Loop counter
int total = 0; // Accumulator

for (index = 0; index < arraySize; index++)
{
total += nums[index];
}
return total;
}
//******************************************************
// average_array
//******************************************************

average_array = total / sum_array;

//******************************************************
// End of Program
//******************************************************


Mel
GeneralRe: C++ help for arrays...average a value Pin
PJ Arends29-Apr-07 17:32
professionalPJ Arends29-Apr-07 17:32 
GeneralRe: C++ help for arrays...average a value Pin
wertyou29-Apr-07 17:42
wertyou29-Apr-07 17:42 
Questionhow to get temp folder path Pin
near2world29-Apr-07 5:04
near2world29-Apr-07 5:04 
AnswerRe: how to get temp folder path Pin
#realJSOP29-Apr-07 6:15
professional#realJSOP29-Apr-07 6:15 
GeneralRe: how to get temp folder path [modified] Pin
near2world30-Apr-07 3:16
near2world30-Apr-07 3:16 
GeneralRe: how to get temp folder path Pin
#realJSOP30-Apr-07 13:05
professional#realJSOP30-Apr-07 13:05 
GeneralRe: how to get temp folder path Pin
near2world1-May-07 0:19
near2world1-May-07 0:19 
AnswerRe: how to get temp folder path Pin
Mark Salsbery29-Apr-07 7:57
Mark Salsbery29-Apr-07 7:57 
GeneralRe: how to get temp folder path Pin
near2world30-Apr-07 3:19
near2world30-Apr-07 3:19 
GeneralRe: how to get temp folder path Pin
Mark Salsbery30-Apr-07 6:13
Mark Salsbery30-Apr-07 6:13 
GeneralRe: how to get temp folder path Pin
near2world1-May-07 0:18
near2world1-May-07 0:18 
AnswerRe: how to get temp folder path Pin
Nibu babu thomas29-Apr-07 17:37
Nibu babu thomas29-Apr-07 17:37 
GeneralRe: how to get temp folder path Pin
near2world30-Apr-07 3:21
near2world30-Apr-07 3:21 
GeneralRe: how to get temp folder path Pin
Nibu babu thomas2-May-07 17:16
Nibu babu thomas2-May-07 17:16 
AnswerRe: how to get temp folder path Pin
Michael Dunn29-Apr-07 20:53
sitebuilderMichael Dunn29-Apr-07 20:53 
GeneralRe: how to get temp folder path Pin
near2world30-Apr-07 3:22
near2world30-Apr-07 3:22 
GeneralRe: how to get temp folder path Pin
Michael Dunn30-Apr-07 12:43
sitebuilderMichael Dunn30-Apr-07 12:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.