I'm a college student in a C++ class. I'm writing a program, and I get the follow error:

[taz3] 3:36pm ~/c++ > gcc stustats-sjs.cpp -o stustats-sjs.app
stustats-sjs.cpp: In function `int main()':
stustats-sjs.cpp:64: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:65: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:66: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:67: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:68: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:69: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:74: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:75: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:76: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:77: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:78: ANSI C++ forbids using pointer to a function in arithmetic
stustats-sjs.cpp:79: ANSI C++ forbids using pointer to a function in arithmetic


I've search google and there's very little information in regards to this error. help!

here's my program:

#include <cmath>

#include <cmath>
#include <cstdlib>
#include <iostream>
#include <iomanip>

void     SetPreciison(int);            

using    namespace std;

int      main      (void)              
{                                      

/*       begin local data space        */
const    int       max = 7;            

int       stuNum[max] = {101,102,103,104,105,106,107};
int       scores[max] = {17,16,15,15,15,14,13};
int		numScores, sumScores;
float	meanAvg, sumMnDvSq, variance, stdDev;
float	mnDev[max],	mnDvSq[max], zscore[max];


/* begin steph's code */

int i = 0;
numScores = 0;
sumScores = 0;

for (i=0; i<max; i++)  {
	numScores = numScores + 1;
	sumScores = sumScores + scores[i];
	}

meanAvg = sumScores/numScores;  
sumMnDvSq = 0;

for (i=0; i<max; i++){
	mnDev[i] = scores[i] - meanAvg;
	mnDvSq[i] = mnDev[i] * mnDev[i];
	sumMnDvSq = sumMnDvSq + mnDvSq[i];

}



variance = sumMnDvSq/numScores - 1;
stdDev = sqrt(variance);

for (i=0; i<max; i++){
	zscore[i] = mnDev[i]/stdDev;
}



/* print column headers */
cout 	<< setw[11] << "STUNUM"
		<< setw[11] << "SCORES"
		<< setw[11] << "MEANDEV"
		<< setw[11] << "MEANDEVSQ"
		<< setw[11] << "ZSCORE"		
		<< setw[11] << "\n\n";
		
		
		
for (i=0; i<max; i++)	{
	cout 	<< setw[11] << stuNum[i]
			<< setw[11] << scores[i]
			<< setw[11] << mnDev[i]
			<< setw[11] << mnDvSq[i]
			<< setw[11] << zscore[i]
			<< setw[11] << endl;	
			
			
}
		

/* end steph's code */



         return(0);                    
}                                      

void     SetPrecision(int pDecPlaces)  
{
         cout.setf(ios::right);        
         cout.setf(ios::fixed);
         cout.setf(ios::showpoint);
         cout.precision(pDecPlaces);
         return;                       
}

Replace setw[ 11 ] with setw(11).

thanks ---)

now I get this, though---

/tmp/cc0p1mMD.o--- In function `main'---
/tmp/cc0p1mMD.o(.text+0x14c) --- undefined reference to `sqrt'
/tmp/cc0p1mMD.o(.text+0x1a6) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x1d1) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x1fc) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x227) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x252) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x27d) --- more undefined references to `setw(int)' follow
/tmp/cc0p1mMD.o--- In function `main'---
/tmp/cc0p1mMD.o(.text+0x29b) --- undefined reference to `cout'
/tmp/cc0p1mMD.o(.text+0x2a0) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x2ab) --- undefined reference to `ostream------operator<<(char const *)'
/tmp/cc0p1mMD.o(.text+0x2b6) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x2c1) --- undefined reference to `ostream------operator<<(char const *)'
/tmp/cc0p1mMD.o(.text+0x2cc) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x2d7) --- undefined reference to `ostream------operator<<(char const *)'
/tmp/cc0p1mMD.o(.text+0x2e2) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x2ed) --- undefined reference to `ostream------operator<<(char const *)'
/tmp/cc0p1mMD.o(.text+0x2f8) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x303) --- undefined reference to `ostream------operator<<(char const *)'
/tmp/cc0p1mMD.o(.text+0x30e) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x319) --- undefined reference to `ostream------operator<<(char const *)'
/tmp/cc0p1mMD.o(.text+0x338) --- undefined reference to `endl(ostream &)'
/tmp/cc0p1mMD.o(.text+0x342) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x383) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x3c4) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x402) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x43b) --- undefined reference to `setw(int)'
/tmp/cc0p1mMD.o(.text+0x474) --- more undefined references to `setw(int)' follow
/tmp/cc0p1mMD.o--- In function `main'---
/tmp/cc0p1mMD.o(.text+0x492) --- undefined reference to `cout'
/tmp/cc0p1mMD.o(.text+0x497) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x4a2) --- undefined reference to `ostream------operator<<(int)'
/tmp/cc0p1mMD.o(.text+0x4ad) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x4b8) --- undefined reference to `ostream------operator<<(int)'
/tmp/cc0p1mMD.o(.text+0x4c3) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x4ce) --- undefined reference to `ostream------operator<<(float)'
/tmp/cc0p1mMD.o(.text+0x4d9) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x4e4) --- undefined reference to `ostream------operator<<(float)'
/tmp/cc0p1mMD.o(.text+0x4ef) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x4fa) --- undefined reference to `ostream------operator<<(float)'
/tmp/cc0p1mMD.o(.text+0x505) --- undefined reference to `ostream & operator<<<int>(ostream &, smanip<int> const &)'
/tmp/cc0p1mMD.o(.text+0x510) --- undefined reference to `ostream------operator<<(ostream &(*)(ostream &))'
/tmp/cc0p1mMD.o--- In function `SetPrecision(int)'---
/tmp/cc0p1mMD.o(.text+0x540) --- undefined reference to `cout'
/tmp/cc0p1mMD.o(.text+0x545) --- undefined reference to `ios------setf(unsigned long)'
/tmp/cc0p1mMD.o(.text+0x555) --- undefined reference to `cout'
/tmp/cc0p1mMD.o(.text+0x55a) --- undefined reference to `ios------setf(unsigned long)'
/tmp/cc0p1mMD.o(.text+0x56a) --- undefined reference to `cout'
/tmp/cc0p1mMD.o(.text+0x56f) --- undefined reference to `ios------setf(unsigned long)'
/tmp/cc0p1mMD.o(.text+0x57e) --- undefined reference to `cout'
/tmp/cc0p1mMD.o(.text+0x583) --- undefined reference to `ios------precision(int)'

I am not a an expert in the Linux programming environment, but here is just a hint. But try using g++ instead of gcc. gcc is usually used for C programs while g++ is used for c++.

Ok here is the code that should work.

I put some coments on some of the things that you did and that I changed.

#include <cmath>

// you dont need this again
// you already included it
// #include <cmath>
#include <cstdlib>
#include <iostream>
#include <iomanip>

void     SetPreciison(int);            

using    namespace std;

// you dont need the void, but you can do it.
//int main (void)
int main()
{                                      

/*       begin local data space        */
const    int       max = 7;            

int     stuNum[max] = {101,102,103,104,105,106,107};
int     scores[max] = {17,16,15,15,15,14,13};
int		numScores, sumScores;
float	meanAvg, sumMnDvSq, variance, stdDev;
float	mnDev[max],	mnDvSq[max], zscore[max];

/* begin steph's code */

int i = 0;
numScores = 0;
sumScores = 0;

for (i=0; i<max; i++)  {
	numScores = numScores + 1;
	sumScores = sumScores + scores[i];
	}

meanAvg = sumScores/numScores;  
sumMnDvSq = 0;

for (i=0; i<max; i++){
	mnDev[i] = scores[i] - meanAvg;
	mnDvSq[i] = mnDev[i] * mnDev[i];
	sumMnDvSq = sumMnDvSq + mnDvSq[i];

}



variance = sumMnDvSq/numScores - 1;
stdDev = sqrt(variance);

for (i=0; i<max; i++){
	zscore[i] = mnDev[i]/stdDev;
}

/* print column headers */
cout.width(11);cout << "STUNUM";
cout.width(11);cout << "SCORES";
cout.width(11);cout << "MEANDEV";
cout.width(11);cout << "MEANDEVSQ";
cout.width(11);cout << "ZSCORE";		
cout.width(11);cout << "\n\n";
		
		
		
for (i=0; i<max; i++)	{
cout.width(11);cout << stuNum[i];
cout.width(11);cout << scores[i];
cout.width(11);cout << mnDev[i];
cout.width(11);cout << mnDvSq[i];
cout.width(11);cout << zscore[i];
cout.width(11);cout << endl;	
			
			
}
		

/* end steph's code */



         return(0);                    
}                                      

void     SetPrecision(int pDecPlaces)  
{
         cout.setf(ios::right);        
         cout.setf(ios::fixed);
         cout.setf(ios::showpoint);
         cout.precision(pDecPlaces);
	 	// This function is void, you shouldn't use return,
      	// but you can.
        // return;                       
}

Note that the following code was wrong:

/* print column headers */
cout 	<< setw[11] << "STUNUM"
		<< setw[11] << "SCORES"
		<< setw[11] << "MEANDEV"
		<< setw[11] << "MEANDEVSQ"
		<< setw[11] << "ZSCORE"		
		<< setw[11] << "\n\n";
		
		
		
for (i=0; i<max; i++)	{
	cout 	<< setw[11] << stuNum[i]
			<< setw[11] << scores[i]
			<< setw[11] << mnDev[i]
			<< setw[11] << mnDvSq[i]
			<< setw[11] << zscore[i]
			<< setw[11] << endl;	
			
			
}

First, setw[11], is not a function from iostream. Second, you use:
"()"<== for functions ===
"[]"<== for arrays ====.
The right function is "width(int)". Any how look in the code that I posted. You will see how it is used. Don't worry about making mistakes like that, that's common in people new to C++ or C. Also please use g++ to compile c++ programs:

g++ stustats-sjs.cpp -o stustats-sjs.app

I also recommend the following website:
www.cppreference.com/
It gives a lot of examples on how use functions from c++.

Take care, good luck and hope I helped some how.


-r

thank you both for your help! between g++ and the improved code, everything's working great. thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.