I am trying to get this program to return a value, but it will not work. Can anyone help?

1.
#include <iostream>
2.
#include <iomanip>
3.
using namespace std;
4.

5.
int number_right (char let1, char let2, char let3, char let4, char let5, char let6);
6.

7.
int main ()
8.
{
9.
char let1 = 0, let2 = 0, let3 = 0, let4 = 0, let5 = 0, let6 = 0;
10.
//call test function
11.
number_right (let1, let2, let3, let4, let5, let6);
12.

13.
}
14.

15.
int number_right (char let1, char let2, char let3, char let4, char let5, char let6) /*function for number_right with six characters taken. Will
16.
return the number of chacter pairs that are a match*/
17.
{
18.
int set1 = 0; //setting set1 as a int, set at 0
19.
int set2 = 0; //setting set2 as a int, set at 0
20.
int set3 = 0; //setting set3 as a int, set at 0
21.

22.
cout << "Please enter six characters.\n"; //promt the user to enter in six characters
23.
cin >> let1 >> let2 >> let3 >> let4 >> let5 >> let6; //user enters six characters
24.

25.
if (let1 == let4) //if the first and fourth characters entered by the user are the same
26.
{
27.
cout << "The first letter is a match.\n"; //will cout notifying user that the numbers are a match
28.
set1 = set1 + 1; //add one to set1 if the characters are the same
29.
}
30.
if (let2 == let5) //if the second and fifth characters entered by the user are the same
31.
{
32.
cout << "The second letter is a match.\n"; //will cout notifying user that the numbers are a match
33.
set2 = set2 + 1; //add one to set2 if the characters are the same
34.
}
35.
if (let3 == let6) //if the third and sixth characters entered by the user are the same
36.
{
37.
cout << "The third letter is a match.\n"; //will cout notifying user that the numbers are a match
38.
set3 = set3 + 1; //add one to set3 if the characters are the same
39.
}
40.
else //if the characters do not match each other
41.
{
42.
cout << "There is no match.\n"; //advising the user that the characters do not match
43.
}
44.

45.
return (set1 + set2 + set3); //returning the additions of set1, set2 and set 3. This will return the correct amount of pairs matched
46.
}

I don't have a compiler on me' laptop here.. but at first glance everything seems to look ok...

Q: how do you know it's not returning the proper value? I see no evidence of any output to determine the return value of number_right( ).

No matter what letter combo I do, it returns a no match.

Ok hombre, let's try this again...

just compile this code and tell me what displays on your DOS console:

#include <iostream>
using namespace std; 

int number_right (char let1, char let2, char let3, char let4, char let5, char let6);  

int main ()
{	

     int matches = 0;	

     char let1 = 0, let2 = 0, let3 = 0, 
          let4 = 0, let5 = 0, let6 = 0;      
     
     cout << "Enter 6 characters:  ";
     cin >> let1 >> let2 >> let3 >> let4 >> let5 >> let6;

     matches = number_right (let1, let2, let3, let4, let5, let6);
     
     cout << "\n\nThere are " << matches << " matches."; 

return 0;
} 

int number_right (char let1, char let2, char let3, char let4, char let5, char let6)	
{

     int set1 = 0, set2 = 0, set3 = 0; 

     if (let1 == let4) 
     {		
          cout << "The first letter is a match.\n"; 
          set1++; 
     }	
     else if (let2 == let5) 
     {		
          cout << "The second letter is a match.\n"; 
          set2++; 
     }		
     else if (let3 == let6) 
     {			
          cout << "The third letter is a match.\n"; 
          set3++; 
     }		
     else 		
     {			
          cout << "There is no match.\n"; 
     } 	

     return (set1 + set2 + set3);
}

Give me specific errors w/ line number (if any)

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.