hilfe beim suchen der fehlenden klammer bzw. ;



  • hallo!

    ich weiß, meine frage klingt vielleicht dumm, aber ich habe anscheinend in meinem sourcecode eine klammer bzw. einen strichpunkt vergessen, weil ich bekomme immer eine fehlermeldung, dass bei dem statement

    switch (Decoration) {
    ...

    ein Strichpunkt vor der { fehlt, und das kann ja nicht sein.

    Leider finde ich den fehler selbst nicht, drum würde ich um hinweise bitten, wie ich der fehlenden symbol auf die schliche kommen kann.
    ich kann bei meinem programm nur dann weiterschreiben, wenn dieses problem behoben ist... 😞

    also, danke für eure hilfe,
    mfg, sinsa.



  • poste bitte den quelltext.

    ansonsten kannst du nur alle klammern im programm ueberpruefen
    oder erstmal alles auskommentieren und dann stueckweise wieder "einkommentieren" bis es nicht mehr geht. dann weisst du wo der fehler ist.



  • das wär die cookie.h-datei

    #ifndef __COOKIE_H__
    #define __COOKIE_H__
    
    #include <string>
    using namespace std;
    
    class Cookie{
    protected:
    	unsigned int weight; 
    	double calFactor; 
    public:
    	Cookie(unsigned int weight, double calFactor);
    	~Cookie(){}
    	virtual unsigned int getCalories()const = 0;
    	virtual string toString();
    	bool operator < (const Cookie &other);  
    	bool operator == (const Cookie &other);
    };
    enum Decoration {
    	nothing,
    	nuts,
    	sugar
    };
    class GingerBread:public Cookie{
    private:
    	Decoration deco;
    public:
    	GingerBread(unsigned int weight, Decoration deco);
    	~GingerBread(){}
    	virtual unsigned int getCalories()const;
    	virtual string toString();
    };
    enum Sugar {
    	noSugar,
    	normal,
    	extreme
    };
    class VanillaCrescent:public Cookie{
    private:
    	Sugar sugar;
    public:
    	VanillaCrescent(unsigned int weight, Sugar sugar);
    	~VanillaCrescent(){}
    	virtual unsigned int getCalories()const;
    	virtual string toString();
    };
    enum Extra {
    	lessSugar,
    	moreNuts
    };
    class CinnamonStar:public Cookie{
    private:
    	Extra extra;
    public:
    	CinnamonStar(unsigned int weight, Extra extra);
    	~CinnamonStar(){}
    	virtual unsigned int getCalories()const;
    	virtual string toString();
    };
    
    #endif
    
    #include <iostream>
    using namespace std;
    
    #include "cookie.h"
    
    #define NULL 0
    
    Cookie::Cookie(unsigned int weight, double calFactor) {
    	this->weight = weight;
    	this->calFactor = calFactor;
    }
    string Cookie::toString(){
      return "Cookie\n";
    }
    bool Cookie::operator <(const Cookie &other) {
    	return (this->getCalories() < other.getCalories());
    }
    bool Cookie::operator ==(const Cookie &other) {
    	return (this->getCalories() == other.getCalories());
    }
    GingerBread::GingerBread(unsigned int weight, Decoration deco) 
    :Cookie(weight, 0.5) {
    	this->deco = deco;
    }
    unsigned int GingerBread::getCalories() const{
    	unsigned int result = 0;
    	result = (unsigned int)(this->weight * this->calFactor);
    	switch (Decoration) {
    	case nothing:
    		result = (unsigned int)(result * 1);
    		break;
    	case nuts:
    		result = (unsigned int)(result * 1.5);
    		break;
    	case sugar:
    		result = (unsigned int)(result * 1.9);
    		break;
    	};
    	return result;
    }
    string GingerBread::toString(){
    	string result = "Gingerbread\t weight: ";	
    	result.append(this->weight);
    	result.append("\tDeco: ");
    	switch(Decoration) {
    		case nothing:
    			result.append("nothing");
    			break;
    		case nuts:
    			result.append("nuts");
    			break;
    		case sugar:
    			result.append("sugar");
    			break;
    	}
    	result.append("\t Calories: ");
    	result.append(this->getCalories());
    	return result;
    }
    VanillaCrescent::VanillaCrescent(unsigned int weight, Sugar sugar) 
    :Cookie(weight, 2.0) {
    	this->sugar = sugar;
    }
    unsigned int VanillaCrescent::getCalories() const{
    	unsigned int result = 0;
    	result = (unsigned int)(this->weight * this->calFactor);
    	switch(Sugar) {
    		case noSugar:
    			result = (unsigned int)(result * 0.5);
    			break;
    		case normal:
    			result = (unsigned int)(result * 1.0);
    			break;
    		case extreme:
    			result = (unsigned int)(result * 1.5);
    			break;
    	  }
    	return result;
    }
    string VanillaCrescent::toString(){
    	string result = "VanillaCrescent\t weight: ";	
    	result.append(this->weight);
    	result.append("\tSugar ");
    	switch(Sugar) {
    		case noSugar:
    			result.append("no");
    			break;
    		case normal:
    			result.append("normal");
    			break;
    		case extreme:
    			result.append("extreme");
    			break;
    	}
    	result.append("\t Calories: ");
    	result.append(this->getCalories());
    	return result;
    }
    CinnamonStar::CinnamonStar(unsigned int weight, Extra extra) 
    :Cookie(weight, 1.2) {
    	this->extra = extra;
    }
    unsigned int CinnamonStar::getCalories() const{
    	unsigned int result = 0;
    	result = (unsigned int)(this->weight * this->calFactor);
    	switch(Extra) {
    	case lessSugar:
    		result = (unsigned int)(result * 0.7);
    		break;
    	case moreNuts:
    		result = (unsigned int)(result * 1.5);
    		break;
    	}
    	return result;
    }
    string CinnamonStar::toString(){
    	string result = "CinnamonStar\t weight: ";	
    	result.append(this->weight);
    	result.append("\tExtra: ");
    	switch(Extra) {
    		case lessSugar:
    			result.append("less sugar");
    			break;
    		case moreNuts:
    			result.append("more nuts");
    			break;
    	}
    	result.append("\t Calories: ");
    	result.append(this->getCalories());
    	return result;
    }
    
    int main(int argc, char* argv[]){
    
    }
    


  • Decoration ist ein struct typ, keine variable. du kannst auch nicht switch auf strukturen oder strings machen, sondern nur auf zahlen (also auch chars, nicht char* oder char[]).



  • das wär die cookie.h-datei

    #ifndef __COOKIE_H__
    #define __COOKIE_H__
    
    #include <string>
    using namespace std;
    
    class Cookie{
    protected:
    	unsigned int weight; 
    	double calFactor; 
    public:
    	Cookie(unsigned int weight, double calFactor);
    	~Cookie(){}
    	virtual unsigned int getCalories()const = 0;
    	virtual string toString();
    	bool operator < (const Cookie &other);  
    	bool operator == (const Cookie &other);
    };
    enum Decoration {
    	nothing,
    	nuts,
    	sugar
    };
    class GingerBread:public Cookie{
    private:
    	Decoration deco;
    public:
    	GingerBread(unsigned int weight, Decoration deco);
    	~GingerBread(){}
    	virtual unsigned int getCalories()const;
    	virtual string toString();
    };
    enum Sugar {
    	noSugar,
    	normal,
    	extreme
    };
    class VanillaCrescent:public Cookie{
    private:
    	Sugar sugar;
    public:
    	VanillaCrescent(unsigned int weight, Sugar sugar);
    	~VanillaCrescent(){}
    	virtual unsigned int getCalories()const;
    	virtual string toString();
    };
    enum Extra {
    	lessSugar,
    	moreNuts
    };
    class CinnamonStar:public Cookie{
    private:
    	Extra extra;
    public:
    	CinnamonStar(unsigned int weight, Extra extra);
    	~CinnamonStar(){}
    	virtual unsigned int getCalories()const;
    	virtual string toString();
    };
    
    #endif
    
    #include <iostream>
    using namespace std;
    
    #include "cookie.h"
    
    #define NULL 0
    
    Cookie::Cookie(unsigned int weight, double calFactor) {
    	this->weight = weight;
    	this->calFactor = calFactor;
    }
    string Cookie::toString(){
      return "Cookie\n";
    }
    bool Cookie::operator <(const Cookie &other) {
    	return (this->getCalories() < other.getCalories());
    }
    bool Cookie::operator ==(const Cookie &other) {
    	return (this->getCalories() == other.getCalories());
    }
    GingerBread::GingerBread(unsigned int weight, Decoration deco) 
    :Cookie(weight, 0.5) {
    	this->deco = deco;
    }
    unsigned int GingerBread::getCalories() const{
    	unsigned int result = 0;
    	result = (unsigned int)(this->weight * this->calFactor);
    	switch (Decoration) {
    	case nothing:
    		result = (unsigned int)(result * 1);
    		break;
    	case nuts:
    		result = (unsigned int)(result * 1.5);
    		break;
    	case sugar:
    		result = (unsigned int)(result * 1.9);
    		break;
    	};
    	return result;
    }
    string GingerBread::toString(){
    	string result = "Gingerbread\t weight: ";	
    	result.append(this->weight);
    	result.append("\tDeco: ");
    	switch(Decoration) {
    		case nothing:
    			result.append("nothing");
    			break;
    		case nuts:
    			result.append("nuts");
    			break;
    		case sugar:
    			result.append("sugar");
    			break;
    	}
    	result.append("\t Calories: ");
    	result.append(this->getCalories());
    	return result;
    }
    VanillaCrescent::VanillaCrescent(unsigned int weight, Sugar sugar) 
    :Cookie(weight, 2.0) {
    	this->sugar = sugar;
    }
    unsigned int VanillaCrescent::getCalories() const{
    	unsigned int result = 0;
    	result = (unsigned int)(this->weight * this->calFactor);
    	switch(Sugar) {
    		case noSugar:
    			result = (unsigned int)(result * 0.5);
    			break;
    		case normal:
    			result = (unsigned int)(result * 1.0);
    			break;
    		case extreme:
    			result = (unsigned int)(result * 1.5);
    			break;
    	  }
    	return result;
    }
    string VanillaCrescent::toString(){
    	string result = "VanillaCrescent\t weight: ";	
    	result.append(this->weight);
    	result.append("\tSugar ");
    	switch(Sugar) {
    		case noSugar:
    			result.append("no");
    			break;
    		case normal:
    			result.append("normal");
    			break;
    		case extreme:
    			result.append("extreme");
    			break;
    	}
    	result.append("\t Calories: ");
    	result.append(this->getCalories());
    	return result;
    }
    CinnamonStar::CinnamonStar(unsigned int weight, Extra extra) 
    :Cookie(weight, 1.2) {
    	this->extra = extra;
    }
    unsigned int CinnamonStar::getCalories() const{
    	unsigned int result = 0;
    	result = (unsigned int)(this->weight * this->calFactor);
    	switch(Extra) {
    	case lessSugar:
    		result = (unsigned int)(result * 0.7);
    		break;
    	case moreNuts:
    		result = (unsigned int)(result * 1.5);
    		break;
    	}
    	return result;
    }
    string CinnamonStar::toString(){
    	string result = "CinnamonStar\t weight: ";	
    	result.append(this->weight);
    	result.append("\tExtra: ");
    	switch(Extra) {
    		case lessSugar:
    			result.append("less sugar");
    			break;
    		case moreNuts:
    			result.append("more nuts");
    			break;
    	}
    	result.append("\t Calories: ");
    	result.append(this->getCalories());
    	return result;
    }
    
    int main(int argc, char* argv[]){
    
    }
    


  • und was kann ich da jetzt tun?
    kann ich case 0:, case 1:, ... schreiben?



  • mach switch(deco) statt switch(Decoration) und erklaere mir, warum du das machen sollst (kleine pruefungsfrage).

    ein paar links fuer ruhige stunden:
    http://www.pronix.de/pronix-4.html
    http://www.lugbz.org/documents/smart-questions_de.html



  • *fasst mal den Problembereich zusammen*

    enum Decoration {
        nothing,
        nuts,
        sugar
    };
    class GingerBread:public Cookie{
    private:
        Decoration deco;
    public:
        GingerBread(unsigned int weight, Decoration deco);
        ~GingerBread(){}
        virtual unsigned int getCalories()const;
        virtual string toString();
    };
    
    unsigned int GingerBread::getCalories() const{
        unsigned int result = 0;
        result = (unsigned int)(this->weight * this->calFactor);
        switch (Decoration) {
        //korrekt: switch (deco) {
        case nothing:
            result = (unsigned int)(result * 1);
            break;
        case nuts:
            result = (unsigned int)(result * 1.5);
            break;
        case sugar:
            result = (unsigned int)(result * 1.9);
            break;
        };
        return result;
    }
    

    "Decoration" ist der Name des Aufzählungstyps, die Variable von diesem Typ, mit der du vergleichen solltest, wäre "deco" (bzw. "this->deco").


Log in to reply