| | |
Homework Function Compile Errors
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
I am having a problem with a program. I have to create a program with about 8 different functions. Which reads in votes, finds the max, the min, prints the votes, prints the max prints the mid, finds the normalization, outputs how many are below .25 and above .75 and prints the normalization. I've got the program typed but I'm coming up with alot of errors when I compile. Can anyone help me out with these problems?
Thanks, SportsFilmer
Here are the errors I'm getting:
p7a.cpp:18: warning: unused variable 'min'
p7a.cpp:18: warning: unused variable 'max'
p7a.cpp: In function 'void print2(double*, int, int)':
p7a.cpp:81: error: no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"The location is")) << std::max'
/usr/local/lib/gcc/sparc64-sun-solaris2.10/4.1.1/../../../../include/c++/4.1.1/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/lib/gcc/sparc64-sun-solaris2.10/4.1.1/../../../../include/c++/4.1.1/bits/ostream.tcc:78: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/lib/gcc/sparc64-sun-solaris2.10/4.1.1/../../../../include/c++/4.1.1/bits/ostream.tcc:90: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
p7a.cpp:90: error: invalid operands of types '<unresolved overloaded function type>' and '<unresolved overloaded function type>' to binary 'operator-'
p7a.cpp:92: error: 'i' was not declared in this scope
p7a.cpp:94: error: 'vote' was not declared in this scope
p7a.cpp:94: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator/'
p7a.cpp: At global scope:
p7a.cpp:98: error: 'top' has not been declared
p7a.cpp: In function 'void normquart(double*, int, int)':
p7a.cpp:100: error: declaration of 'int bottom' shadows a parameter
p7a.cpp:101: error: 'i' was not declared in this scope
p7a.cpp:103: error: 'vote' was not declared in this scope
p7a.cpp:103: error: expected primary-expression before '<' token
p7a.cpp:106: error: expected `(' before 'else'
p7a.cpp: At global scope:
p7a.cpp:114: error: expected initializer before numeric constant
Thanks, SportsFilmer
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std; void readData (double []); void print1 (double []); int findmax (double []); int findmin (double []); void print2 (double [], int, int); void norm (double [], int, int); void normquart (double [], int, int); void print3 (double []); int main () { int maxloc, minloc, range, bottom = 0, top = 0; double votes [50], min = votes[minloc], max = votes[maxloc]; readData (votes); print1 (votes); maxloc=findmax (votes); minloc=findmin (votes); print2 (votes, maxloc, minloc); norm (votes, maxloc, minloc); normquart (votes, bottom, top); print3 (votes); return 0; } void readData (double votes []) { for (int i=0; i<50; i++) { cin>> votes [i]; } } void print1 (double votes []) { for (int i=0; i<50; i++) { cout<< votes[i] <<endl; } } int findmax (double votes []) { int max=0; for (int i=1; i<50; i++) { if (votes [i]>votes[max]) { max=i; } } return max; } int findmin (double votes []) { int min=0; for (int i=1; i<50; i++) { if (votes [i]<votes[min]) { min=i; } } return min; } void print2 (double votes[], int maxloc, int minloc) { cout<< "The maximum value is" <<votes[maxloc]; cout<< "The location is" <<max <<endl; cout<< "The minimum value is" <<votes[minloc]; cout<< "The location is" <<min <<endl; } void norm (double votes[], int maxloc, int minloc) { max=votes[maxloc]; min=votes[minloc]; range = max-min; { for (i=0;i<50;i++) { vote[i]=(vote[i]-min)/range; } } } void normquart (double votes[], int bottom, int top) { for (i=0; i<50; i++) { { if (vote[i]=<0.25) bottom++; } { if else (vote [i]=>0.75) top++; } } cout<<"The number of nromalized values in the bottom is: " <<bottom; cout<<"The number of nromalized values in the top is: " <<top; } void print 3 (double votes[]) { for (i=0; i<50; i++) { cout<<"This is a record of the votes normalized: " << votes[i]; } }
Here are the errors I'm getting:
p7a.cpp:18: warning: unused variable 'min'
p7a.cpp:18: warning: unused variable 'max'
p7a.cpp: In function 'void print2(double*, int, int)':
p7a.cpp:81: error: no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"The location is")) << std::max'
/usr/local/lib/gcc/sparc64-sun-solaris2.10/4.1.1/../../../../include/c++/4.1.1/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/lib/gcc/sparc64-sun-solaris2.10/4.1.1/../../../../include/c++/4.1.1/bits/ostream.tcc:78: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/lib/gcc/sparc64-sun-solaris2.10/4.1.1/../../../../include/c++/4.1.1/bits/ostream.tcc:90: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
p7a.cpp:90: error: invalid operands of types '<unresolved overloaded function type>' and '<unresolved overloaded function type>' to binary 'operator-'
p7a.cpp:92: error: 'i' was not declared in this scope
p7a.cpp:94: error: 'vote' was not declared in this scope
p7a.cpp:94: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator/'
p7a.cpp: At global scope:
p7a.cpp:98: error: 'top' has not been declared
p7a.cpp: In function 'void normquart(double*, int, int)':
p7a.cpp:100: error: declaration of 'int bottom' shadows a parameter
p7a.cpp:101: error: 'i' was not declared in this scope
p7a.cpp:103: error: 'vote' was not declared in this scope
p7a.cpp:103: error: expected primary-expression before '<' token
p7a.cpp:106: error: expected `(' before 'else'
p7a.cpp: At global scope:
p7a.cpp:114: error: expected initializer before numeric constant
Most of the errors you get are typing errors I presume.
For instance, a lot of times you use max or min, where you're giving min or maxloc as argument to the function.
Also some variables are just not declared in a function, remember that each function has it's own variables if they are not declared globally or given as arguments.
EDIT:
a second look at your code tells me that some errors you are having are also forgetting { or not knowing the syntaxis.
Also, in your main function you have this:
The problem with this code is that maxloc and minloc are not initialised, which means they can be any value. You have to give them a startvalue, (I don't know how your program works, just corrected some errors quickly)
Hopefully this can help you further...
For instance, a lot of times you use max or min, where you're giving min or maxloc as argument to the function.
Also some variables are just not declared in a function, remember that each function has it's own variables if they are not declared globally or given as arguments.
EDIT:
a second look at your code tells me that some errors you are having are also forgetting { or not knowing the syntaxis.
Also, in your main function you have this:
cpp Syntax (Toggle Plain Text)
int main() { int maxloc, minloc, range, bottom = 0, top = 0; double votes [50], min=votes[minloc], max=votes[maxloc]; }
The problem with this code is that maxloc and minloc are not initialised, which means they can be any value. You have to give them a startvalue, (I don't know how your program works, just corrected some errors quickly)
Hopefully this can help you further...
Last edited by brechtjah; Nov 20th, 2008 at 8:15 pm.
RTFM - Read The Full Message
They tell you where the problem is and what it is. Even if you don't fully understand the messages, they're pointing you to the problems. Look closely.
They tell you where the problem is and what it is. Even if you don't fully understand the messages, they're pointing you to the problems. Look closely.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- Please help with Pointers, Classes, Virtual Functions, and Abstract Classes (C++)
- type 'double' unexpected (C)
- C++ Programming issue (C++)
- Help with 1.pointers and 2.error checking (C++)
- Using a struct array (C++)
- only a couple of hours to go... (C++)
- Passing a matrix from main function to user defined function. (C++)
- Dynamic memory allocation homework (C++)
Other Threads in the C++ Forum
- Previous Thread: help :S
- Next Thread: Linked List of struct
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






