Character

The program should ask the user about the continuation of executing a program and the answer should be y or Y or any word or sentences starts with y or Y.

while (yesOrNo == 'y' || yesOrNo == 'Y' || ??????);

I don't know how to write a boolean expression that include all words and sentences starting with y and Y?

You can check the first character of the string and check if it starts with Y or y.
I don't know with what principle write it? Is it sorting?
1
2
3
4
#include <string>
#include <cctype>

using namespace std;


1
2
3
4
string yesOrNo;
cin >> yesOrNo;

while ( tolower(yesOrNo[0]) == 'y' )



http://www.cplusplus.com/reference/cctype/tolower/
http://www.cplusplus.com/reference/string/string/operator%3E%3E/
http://www.cplusplus.com/reference/string/string/operator[]/
Last edited on
@chervil

invalid types 'char[int]' for array subscript

It gives me this error.

int main() {
int feet = 0, inches = 0, meters = 0, centimeters = 0;
double dfeet, dmeter; char yesOrNo;
do {

cout << "enter 1 for feet,inches to meters,centimeters, or\nenter 2 for meters,centimeters to feet,inches\n";
cin >> choose;

while (choose != 1 && choose != 2) {
cout << "enter 1 or 2 only\n";
cin >> choose;
}

if (choose == 1) { //conversion of feet, inches to meters, centimeters
getLengthf(feet, inches);
dfeet = feetPlusFraction(feet, inches);
convertToMeter(dfeet, meters, centimeters);
resultToMeter(meters, centimeters);
}

else if (choose == 2) {
getLenghtm(meters, centimeters);
dmeter = meterPlusFraction(meters, centimeters);
convertToFeet(dmeter, feet, inches);
resultToFeet(feet, inches);
}
cout << "convert more?\n";
string yesOrNo;
cin >> yesOrNo;
}//end of do statement
while (tolower(yesOrNo[0]) == 'y')

return 0;
}
Last edited on
You have two completely separate variables with the same name, yesOrNo

 
char yesOrNo;

 
string yesOrNo;


Change the first from char to string. Delete the second.

Also, could you use code tags please, to make the code easier to read, and the indentation show properly (see article):

http://www.cplusplus.com/articles/jEywvCM9/

Topic archived. No new replies allowed.