|
-
September 12th, 2008, 01:41 AM
#1
invalid operands of types 'const char[13]' and 'char*' to binary 'operator+'
I don't understand where the const char is coming from.
As mentioned in the title, the error I'm getting is " invalid operands of types 'const char[13]' and 'char*' to binary 'operator+'".
Am I using strcat incorrectly?
(BTW I'm barely starting to learn C++, so I'm sure it's not as well written as it could be... just trying to understand the fundamentals)
Code:
#include <iostream>
#include <string>
#include <windows.h>
#include <sstream>
#include <convert.h> //custom header I made, enables me to use
//"string mystring = stringify(double)"
char chQuit = 'n';
using namespace std;
char chDir;
char* chNewLength;
char* chCurrentLength;
char* chLengthWhole;
char* chUnitSingular;
double doLength;
double doResult;
double doResultWhole = '0';
string strResultWhole;
//Converts Inches to Centimeters
double fromInches (double Length) {
double doReturn;
doReturn = ((Length) * 2.54);
chCurrentLength="Inches";
chNewLength="Centimeters";
chLengthWhole=" Meters";
chUnitSingular="Meter";
if (doReturn >= 100) {
doResultWhole = (doReturn / 100);
}
else {doResultWhole = 0;
}
return (doReturn);
}
//Converts Centimeters to Inches
double fromCentimeters (double Length) {
double doReturn;
doReturn = ((Length) / 2.54);
chCurrentLength="Centimeters";
chNewLength="Inches";
chLengthWhole=" Feet";
chUnitSingular="Foot";
if (doReturn >=12) {
doResultWhole = (doReturn / 12);
}
else { doResultWhole = 0;
}
return (doReturn);
}
int main(){
chQuit = 'n';
do{
chQuit = 'n';
system("cls");
cout << "Are you converting FROM (I)nches or (C)entimeters?" <<endl;
cout << "(I/C): ";
cin >> chDir;
if (chDir == 'I' || chDir == 'i') {
chCurrentLength="Inches";
}
else if (chDir == 'C' || chDir == 'c') {
chCurrentLength="Centimeters";
}
cout << "Enter length in " << chCurrentLength << endl;
cin >> doLength;
if (doResultWhole !=0) {
strResultWhole = (stringify(doResultWhole));
}
else {strResultWhole= strchr("Less than a " + chUnitSingular);}
//Problem is here ^
if (chDir == 'I' || chDir == 'i') {
cout << fromInches(doLength) << endl << "(" << strResultWhole << ")" << endl;
}
else if (chDir == 'C' || chDir == 'c') {
cout << fromCentimeters(doLength) << endl << "(" << strResultWhole << ")" << endl;
}
cout << "Do you want to convert another length?" << endl;
cout << "(Y/N)";
cin >> ::chQuit;}
while (chQuit == 'Y' || chQuit == 'y');
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|