dudis_sutis2br 0 Posted December 15, 2020 Report Share Posted December 15, 2020 toda fez que executo este programa ele so imprimi a pergunta eu respondo e ele fecha sem a resposta #include <iostream> using namespace std; int main() { cout << "ola tudo bem? " << endl; int a = 0; cin >> a; string b = ("tudo"), c = ("não"); switch(a){ case 'b': cout << "que bom" << endl; break; case 'c': cout << "ah, me desculpe" << endl; } return 0; } Quote Link to post Share on other sites
0 vangodp 0 Posted December 25, 2020 Report Share Posted December 25, 2020 Não é possivel usar switch para comparar strings, somente chars, ints etc, ou seja tipos básicos. Para fazer o que você quer use if. #include <iostream> using namespace std; int main() { cout << "ola tudo bem? " << endl; string a = "não", b = "tudo", c = "não"; if(a == b) { cout << "que bom" << endl; } else if(a == c) { cout << "ah, me desculpe" << endl; } return 0; } Quote Link to post Share on other sites
Question
dudis_sutis2br 0
toda fez que executo este programa ele so imprimi a pergunta eu respondo e ele fecha sem a resposta
Link to post
Share on other sites
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.