RSS Forums RSS

Homework Function Compile Errors

Please support our C++ advertiser: Programming Forums
Reply
Posts: 1
Reputation: SoprtsFilmer is an unknown quantity at this point 
Solved Threads: 0
SoprtsFilmer SoprtsFilmer is offline Offline
Newbie Poster

Homework Function Compile Errors

  #1  
Nov 20th, 2008
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

#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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 89
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Re: Homework Function Compile Errors

  #2  
Nov 20th, 2008
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:
  1. int main() {
  2. int maxloc, minloc, range, bottom = 0, top = 0;
  3. double votes [50], min=votes[minloc], max=votes[maxloc];
  4. }

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 7:15 pm.
Reply With Quote  
Posts: 1,495
Reputation: vmanes is a name known to all vmanes is a name known to all vmanes is a name known to all vmanes is a name known to all vmanes is a name known to all vmanes is a name known to all 
Solved Threads: 167
vmanes's Avatar
vmanes vmanes is offline Offline
Nearly a Posting Virtuoso

Re: Homework Function Compile Errors

  #3  
Nov 21st, 2008
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.
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 496 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:29 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC