mercredi 9 février 2022

no viable conversion from 'std::__1::string

I am trying to write code where the user inputs a color and if they use upper case letters it converts it to lowercase. After that the users input is ran through another function is_rainbow. This functions checks if the color the user gave is part of the rainbow. At the end it should return either a 0 or 1 if it part of the rainbow. I am getting long error message. Any resource I can read upon or any sort of help.

#include <iostream>
#include <cmath>
#include <cstring>
#include<algorithm>

using namespace std;

bool is_rainbow(string color){
bool red = color1 == 'red';
bool orange = color1 == 'orange';
bool yellow = color1 == 'yellow';
bool green = color1 == 'green';
bool blue = color1 == 'blue';
bool indigo = color1 == 'indigo';
bool violet = color1 == 'violet';
return red || orange || yellow || green || blue || indigo || violet;
}



int main()
{
string user_color;
cout << "Checkes to see if color is part of rainbow \nAdd one color: ";
getline(cin, user_color);   
// Converts users input to lower case letters
std:: transform(user_color.begin(), user_color.end(), user_color.begin(), ::tolower);
cout << is_rainbow(user_color);
return 0;

Aucun commentaire:

Enregistrer un commentaire