Beginner Help, Win 32

P

PhreakRox

Hello, I am new to c++ Win32 coding, actually this is the first time
Ive really tried to make a program with it. I was trying to create a
"love calculator" program, this exerpt is tha part which compares the
length of the 2 different names. It does not compile, and instead
gives me 3 errors and 4 warnings, could someone please tell me what I
am doing wrong? Help would be greatly appreciated.

Errors/Warnings:

Warning 1 warning C4267: 'initializing' : conversion from 'size_t' to
'int', possible loss of data
Warning 2 warning C4018: '<' : signed/unsigned mismatch
Warning 3 warning C4267: 'initializing' : conversion from 'size_t' to
'int', possible loss of data
Warning 4 warning C4018: '<' : signed/unsigned mismatch116
Error 5 error C3867: 'std::basic_string<_Elem,_Traits,_Ax>::length':
function call missing argument list; use
'&std::basic_string<_Elem,_Traits,_Ax>::length' to create a pointer to
member
Error 6 error C2446: '==' : no conversion from '__w64 unsigned int' to
'__w64 unsigned int (__thiscall std::basic_string<_Elem,_Traits,_Ax>::*
)(void) const'
Error 7 error C2040: '==' : '__w64 unsigned int (__thiscall
std::basic_string<_Elem,_Traits,_Ax>::* )(void) const' differs in
levels of indirection from '__w64 unsigned int'

Code:


int Calculate(string p1FirstName, string p1LastName, string
p2FirstName, string p2Lastname, string p1Sex, string p2Sex)
{
int Percentage = 0;
if (p1FirstName.length() > p2FirstName.length())
{
int x = p2FirstName.length();
int i = 10;
while ( x < p1FirstName.length() )
{
x++;
i--;
}
Percentage += i;
}
else if (p1FirstName.length() < p2FirstName.length())
{
int x = p1FirstName.length();
int i = 10;
while ( x < p2FirstName.length() )
{
x++;
i--;
}
Percentage += i;

}
else if (p1FirstName.length == p2FirstName.length())
{
Percentage += 10;
}
return Percentage;
}
 
A

aj

check your last "else if". Your first call to length on this line is
missing the "()".

-- AJ
 
P

PhreakRox

Thankyou for your help, however im still experiancing one more problem.
The percentage I return does not seem to display. I was just
wondering if I was using ostringstream correctly.

I tried both this:

std::eek:stringstream strstream;
strstream << "Full Name: " + Response[0] + " " + Response[1] + " your
compatibility with " + Response[3] + " " + Response[4] + " is " <<
percent.c_str() << "%";
echo(strstream.str(), 1);

and this:


std::eek:stringstream strstream;
strstream << "Full Name: " + Response[0] + " " + Response[1] + " your
compatibility with " + Response[3] + " " + Response[4] + " is " <<
percent << "%";
echo(strstream.str(), 1);
 
S

Stuart Golodetz

PhreakRox said:
Thankyou for your help, however im still experiancing one more problem.
The percentage I return does not seem to display. I was just
wondering if I was using ostringstream correctly.

I tried both this:

std::eek:stringstream strstream;
strstream << "Full Name: " + Response[0] + " " + Response[1] + " your
compatibility with " + Response[3] + " " + Response[4] + " is " <<
percent.c_str() << "%";

strstream << "Full Name: " << Response[0] << " " << Response[1] << " etc.";

HTH,
Stu

P.S. I wouldn't call it strstream, there's something in the standard library
called that and it could be confusing :)

<snip>
 
P

PhreakRox

Thankyou for your help stuart, that did the trick for me

Stuart said:
PhreakRox said:
Thankyou for your help, however im still experiancing one more problem.
The percentage I return does not seem to display. I was just
wondering if I was using ostringstream correctly.

I tried both this:

std::eek:stringstream strstream;
strstream << "Full Name: " + Response[0] + " " + Response[1] + " your
compatibility with " + Response[3] + " " + Response[4] + " is " <<
percent.c_str() << "%";

strstream << "Full Name: " << Response[0] << " " << Response[1] << " etc.";

HTH,
Stu

P.S. I wouldn't call it strstream, there's something in the standard library
called that and it could be confusing :)

<snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top