Test c++ prog...



  • ich hab ma was verushct:

    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    float schlecht;
    float gut;
    float gehn;
    cout<<"Geht es dir GUT oder SCHLECHT"<<endl;
    cin>> gehn;
    if(gehn=schlecht)
    {
    cout<<"Das ist Schade"<<endl;
    }
    else if(gehn=gut)
    {
                  cout<<"Das ist wunderbar"<<endl;
                  }
    else
      cout<<"Das ist keine antwort. Antworte mit gut oder schlecht"<<endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    

    leider funzt das net wies soll.
    Was muss ich anders machen?



  • Ich würd erstmal grundlegende Dinge lernen... Da is ja eigentlich alles falsch was man falsch machen kann! 🙂



  • #include <cstdlib>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
       string schlecht = "schlecht";
       string gut = "gut";
       string gehn;
       cout << "Geht es dir GUT oder SCHLECHT" << endl;
       cin >> gehn;
    
       if(gehn == schlecht) {
          cout << "Das ist Schade" << endl;
       } else if(gehn == gut) {
          cout << "Das ist wunderbar" << endl;
       } else {
          cout << "Das ist keine antwort. Antworte mit gut oder schlecht" << endl;
       }
       system("PAUSE");
       return EXIT_SUCCESS;
    }
    

    Ich würde auch sagen such dir ein gutes Tutorial!



  • Hi!

    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <cctype>
    
    int main()
    {
    	std::string emotion;
    
    	std::cout << "Geht es dir GUT oder SCHLECHT" << std::endl;
    	std::getline( std::cin, emotion );
    	std::transform( emotion.begin(), emotion.end(), emotion.begin(), std::toupper );
    
    	if ( emotion == "GUT" )
    	{
    		std::cout << "Das ist wunderbar" << std::endl;
    	}
    	else if ( emotion == "SCHLECHT" )
    	{
    		std::cout << "Das ist Schade" << std::endl;
    	}
    	else
    	{
    		std::cout << "Das ist keine antwort. Antworte mit gut oder schlecht" << std::endl;
    	}
    
    	std::cin.clear();
    	std::cin.get();
    	return 0;
    }
    

    Yo!



  • David_pb schrieb:

    std::transform( emotion.begin(), emotion.end(), emotion.begin(), std::toupper );
    

    Na ja, das würde ich nem Anfänger nicht gerade zumuten...er weiß ja nicht mal was std::string ist, sonst würde er nicht mit float rummurksen.


Anmelden zum Antworten