powtorzenie uzywajac bool i sprawdzenie czy wprowadzona litera to samogloska
Ostatnio zmodyfikowano 2017-12-04 21:28
TaRaNTuLaH Temat założony przez niniejszego użytkownika |
powtorzenie uzywajac bool i sprawdzenie czy wprowadzona litera to samogloska » 2017-12-04 16:12:26 Czesc ! Pisze program ktory sprawdza czy wprowadzona litera to samogloska i przy okazji pozwala nam kontynuoowac jesli wybierzemy taka opcje. Jednak mam dwa problemy Pierwszy: Jesli wpisze np. "slowo". Na poczatku pokaze, ze to nie jest litera - czyli poprawnie, jednak jesli wybiore kontynuuacje pokaze, ze to nie samogloska (wezmie literke 's' a nastepnie znowu zapyta chce kontynuuowac [wykona sie drugi while, a tego nie chce]) Drugi: Chce zeby nie wykonywalo drugiego while'a po tym jak przy pierwszym klikne kontynuuj (ale reszte kodu juz tak) i troche utknalem :/ KOD: #include <iostream> #include <string> using namespace std;
int main( int argc, char ** argv ) { char check; char cont; string onlyone; cout << "Hello I am gonna check if letter that you have entered is vowel!"; bool start = true; while( start ) { cout << "\nPlease enter your letter: "; cin >> onlyone; check = onlyone[ 0 ]; if( onlyone.size() > 1 ) { bool powtorka = true; cout << "It's not even a letter! "; while( powtorka ) { cout << "\nEnter Y/y if you want to continue, if you want to stop, enter any other letter.\n"; cin >> cont; if( cont == 'y' || cont == 'Y' ) powtorka = false; else start = false, powtorka = false; } if( start == false ) return 0; } if( check >= 65 && check <= 122 ) { if( check == 'a' ) { cout << "It's a vowel!"; } else if( check == 'A' ) { cout << "It's a vowel!"; } else if( check == 'e' ) { cout << "It's a vowel!"; } else if( check == 'E' ) { cout << "It's a vowel!"; } else if( check == 'o' ) { cout << "It's a vowel!"; } else if( check == 'O' ) { cout << "It's a vowel!"; } else if( check == 'i' ) { cout << "It's a vowel!"; } else if( check == 'I' ) { cout << "It's a vowel!"; } else if( check == 'u' ) { cout << "It's a vowel!"; } else if( check == 'U' ) { cout << "It's a vowel!"; } else if( check == 'y' ) { cout << "It's a vowel!"; } else if( check == 'Y' ) { cout << "It's a vowel!"; } else cout << "It's not a vowel!"; } bool powtorka = true; while( powtorka ) { cout << "\nEnter Y/y if you want to continue, if you want to stop, enter any other letter."; cin >> cont; if( cont == 'y' || cont == 'Y' ) powtorka = false; else start = false, powtorka = false; } } return 0; }
|
|
DanielMagical |
JD » 2017-12-04 19:02:13 JD JD JD JD
LEPIEJ ZRÓB SB TRÓJKĄT PASCALA KTO WYBIŁ TEN Z@P3RD@1@
#include <iostream> int main(){ int ** t; int * b; int r1, r2=1, a; std::cin >> a; r1=a+1; t = new int*[r1]; for(int i=0;i<r1;++i){ r2 = 1+i; t=new int[r2]; t[0]=r2; } t[0][1]= 1; t[1][1]= 1; t[1][2]= 1; for(int i=2;i<r1;++i){ t[1]= 1; t[t[0]-1] = 1; for(int j=2;j<t[0]-1;++j){ t[j]=t[i-1][j-1]+t[i-1][j]; } } for(int i=0;i<r1;++i){ for(int e=0;e<r1-i;++e) std::cout << " "; for(int j=1;j<t[0];++j){ std::cout << "[" << t[j] << "]" ; } std::cout << std::endl; }
return 0; }
|
|
RazzorFlame |
» 2017-12-04 19:34:14 @up rak, ban. @topic: O to Ci chodziło? #include <iostream> #include <string> #include <cctype> using namespace std;
int main( int argc, char ** argv ) { const std::string vowels( "aeoiuy" ); char check; char cont; string onlyone; cout << "Hello I am gonna check if letter that you have entered is vowel!"; bool start = true; while( start ) { cout << "\nPlease enter your letter: "; cin >> onlyone; check = onlyone[ 0 ]; if( onlyone.size() > 1 ) { bool powtorka = true; cout << "It's not even a letter! "; while( powtorka ) { cout << "\nEnter Y/y if you want to continue, if you want to stop, enter any other letter.\n"; cin >> cont; if( cont == 'y' || cont == 'Y' ) powtorka = false; else start = false, powtorka = false; } if( start == false ) return 0; } if( vowels.find( std::tolower( check ) ) != std::string::npos ) std::cout << "Its a vowel." << std::endl; else std::cout << "It is not a vowel." << std::endl; if( onlyone.length() <= 1 ) { bool powtorka = true; while( powtorka ) { cout << "\nEnter Y/y if you want to continue, if you want to stop, enter any other letter."; cin >> cont; if( cont == 'y' || cont == 'Y' ) powtorka = false; else start = false, powtorka = false; } } } return 0; }
|
|
TaRaNTuLaH Temat założony przez niniejszego użytkownika |
» 2017-12-04 20:33:03 @Razzorflame Tak o to :D Z tym, że jak wpiszę np "dwa" potem y, żeby kontynuować to pokaże "It's not a vowel", wiesz może jak się tego pozbyć? :D I do czego służy std::string::npos (konkretnie npos) ;)
Dziękuję ! :D |
|
YooSy |
» 2017-12-04 20:41:23 |
|
TaRaNTuLaH Temat założony przez niniejszego użytkownika |
» 2017-12-04 21:28:06 Dzięki @YooSy ;)
Niestety przy wpisywaniu dwóch wyrazów program się wysypuje :( przy np "stop now" wyrzuca na ekran o kontynuowaniu a potem wyrzuca return :/ |
|
« 1 » |