trouble in call my own function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rabbitysun
    New Member
    • Feb 2013
    • 3

    trouble in call my own function

    i'm just a beginner in c++
    my assignment was to wrote the functions.
    i tried to write a main to test it.
    but i could call it correctly/.
    Code:
    #include <iostream>
    #include <algorithm>
    #include <string>
    using namespace std;
    
    bool chars(char x)
    	{
    		if (((x<=90)&&(x>=65))||((x<=122)&&(x>=97)))
    			return false;
    		else return true;
    	}
    
    
    int transformCriteria(unsigned int distances[], std::string words1[],std::string words2[],unsigned int nCriteria)
    {
    	int z;
    	for (int i=0; i<nCriteria;i++)
    	{	
    		int s1= words1[i].size();
    		int s2= words2[i].size();
    		string originalWord1=words1[i];
    		string originalWord2=words2[i];
    		
    		
    		words1[i].erase(std::remove_if(words1[i].begin(), words1[i].end(), &chars), words1[i].end());
    			
    		
    		words2[i].erase(std::remove_if(words2[i].begin(), words2[i].end(), &chars), words2[i].end());
    		
    		for (int s=0; s<s1; s++)
    		{
    			words1[i][s]=words1[i][s]+32;
    		}
    		for (int s=0; s<s2; s++)
    		{
    			words2[i][s]=words2[i][s]+32;
    		}
    		if ((originalWord1!=words1[i])||(originalWord2!=words2[i]))
    			z++;
    	}
    	return z;
    
    }
    
    int main()
    {
    	string n1[3]={ "teacher", "teacher", "teacher2"};
    	string n2[3]={ "teacher11", "teacher", "teacher22"};
    	unsigned int q=3;
    	unsigned int p[]={2,3,4};
    	cout << transformCriteria(p[], n1[], n2[], q)<< endl;//here is where mistakes happen
    }
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    What errors did you observe?

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      When you call transformationC riteria, the array is p and not p[]. You will need to fix the other arrays also in the call statement.

      You are confusing the declaration of an array p[] with the actual array p.
      Last edited by weaknessforcats; Feb 18 '13, 03:59 PM. Reason: typo

      Comment

      Working...