Programm problem nich komplierbar



  • Hallo,
    ich habe folgendes programm geschrieben und bekommen dann immer eine fehlermeldung und kann leider den fehelr nicht finden, Ich hoffe ihr könnt mir helfen. Vielen dank
    // This programm calculates average temperature
    #include <iostream>
    #include <iomanip>
    using namespace std;

    struct temp
    {
    double temp [12];
    double rainfall [12];
    };
    double SumArrayR (double[], int);

    double gethighestR (double [], int);

    double getlowestR (double [], int);

    double gethighestTemp (double[], int);

    double getlowestTemp (double[], int);

    int main ()
    {
    const int months = 12;
    double rainfall [months],
    temp [months],
    totalR,
    highestR,
    lowestR,
    averageR,
    totalTemp,
    highestTemp,
    lowestTemp,
    averageTemp;
    //Get the rainamount of every months
    cout << "Enter the amount of rain for every months.\n";
    for (int count = 0; count < months; count++)
    {
    cout << "Months" << (count +1) <<": ";
    cin >> rainfall [count];
    }
    // Get the temperature of every months
    cout << "Enter the average temperature of every months. \n";
    for (int count = 0; count < months; count++)
    {
    cout << "Months" << (count +1) <<": ";
    cin >> temp [count];
    }
    totalR = SumArrayR (rainfall, months);

    averageR = totalR/ months;

    highestR = gethighestR (rainfall, months);

    lowestR = getlowestR (rainfall, months);

    averageTemp =totalTemp/ months;

    highestTemp = gethighestTemp (temp, months);

    lowestTemp = getlowestTemp (temp, months);

    cout << fixed << showpoint << setprecision (2);
    cout << "The total amount of rainfall is " << totalR << endl;
    cout << "The average amount of rainfall is " << averageR << endl;
    cout << "The highest amount of rainfall is " << highestR << endl;
    cout << "The lowest amount of rainfall is " << lowestR << endl;
    cout << "The average temperature was " << totalTemp << endl;
    cout << "The lowest temperature was " << lowestTemp << endl;
    cout << "The highest temperature was" <<highestTemp << endl;
    getchar();

    std::cin.clear();
    std::cin.ignore(std::cin.rdbuf()->in_avail());
    std::cin.get();
    return 0;
    }
    double sumArrayR (double array [], int size)
    {
    double totalR = 0;
    for (int count = 0; count < size; count++)
    totalR += array [count];
    return totalR;
    }

    double gethighestR (double array [], int size)
    {
    double highestR;
    highestR = array [0];
    for (int count = 1; count < size; count++)
    {
    if (array [count] > highestR)
    highestR = array[count];
    }
    return highestR;
    }

    double getlowestR (double array[], int size)
    {
    double lowestR;
    lowestR = array [0];

    for ( int count = 1; count < size; count++)
    {
    if (array[count] < lowestR)
    lowestR = array[count];
    }
    return lowestR;
    }

    double gethighestTemp (double array [], int size)
    {
    double highestTemp;
    highestTemp = array [0];
    for (int count = 1; count < size; count++)
    {
    if (array [count] > highestTemp)
    highestTemp= array [count];
    }
    return highestTemp;
    }
    double getlowestTemp (double array [], int size)
    {
    double lowestTemp;
    lowestTemp = array [0];
    for (int count = 1; count < size; count++)
    {
    if (array [count] < lowestTemp)
    lowestTemp = array[count];
    }
    return lowestTemp;
    }

    meine fehlermeldung:
    C:\DOKUME1\Amilo\LOKALE1\Temp\ccakbaaa.o(.text+0x25f) In function main': [Linker error] undefined reference toSumArrayR(double*, int)'
    C:\DOKUME1\Amilo\LOKALE1\Temp\ccakbaaa.o(.text+0x25f) ld returned 1 exit status



  • Du musst die Funktion vor main() deklarieren, damit sie bekannt ist. Du kannst sie auch gleich dort definieren, aber das ist dir überlassen.

    Benutze bitte C++-Tags, d.h. hülle den Code in [cpp] und [/cpp] ein. Das sieht dann folgendermassen aus:

    int main()
    {
        return 0;
    }
    


  • Nexus schrieb:

    Du musst die Funktion vor main() deklarieren, damit sie bekannt ist. Du kannst sie auch gleich dort definieren, aber das ist dir überlassen.

    Die Funktionen sind doch vor der main() deklariert, sieht man nur so schlecht 😛

    // This programm calculates average temperature
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    struct temp
    {
    	double temp [12];
    	double rainfall [12];
    };
    double SumArrayR (double[], int); // hier mit GROSSEM S geschrieben
    
    double gethighestR (double [], int);
    
    double getlowestR (double [], int);
    
    double gethighestTemp (double[], int);
    
    double getlowestTemp (double[], int);
    
    int main ()
    {
    	const int months = 12;
    	double rainfall [months],
    	temp [months],
    	totalR,
    	highestR,
    	lowestR,
    	averageR,
    	totalTemp,
    	highestTemp,
    	lowestTemp,
    	averageTemp;
    
    	//Get the rainamount of every months
    	cout << "Enter the amount of rain for every months.\n";
    
    	for (int count = 0; count < months; count++)
    	{
    		cout << "Months" << (count +1) <<": ";
    		cin >> rainfall [count];
    	}
    	// Get the temperature of every months
    
    	cout << "Enter the average temperature of every months. \n";
    
    	for (int count = 0; count < months; count++)
    	{
    		cout << "Months" << (count +1) <<": ";
    		cin >> temp [count];
    	}
    
    	totalR = SumArrayR (rainfall, months); // Hier auch mit GROSSEM S geschrieben
    
    	averageR = totalR/ months;
    
    	highestR = gethighestR (rainfall, months);
    
    	lowestR = getlowestR (rainfall, months);
    
    	averageTemp =totalTemp/ months;
    
    	highestTemp = gethighestTemp (temp, months);
    
    	lowestTemp = getlowestTemp (temp, months);
    
    	cout << fixed << showpoint << setprecision (2);
    	cout << "The total amount of rainfall is " << totalR << endl;
    	cout << "The average amount of rainfall is " << averageR << endl;
    	cout << "The highest amount of rainfall is " << highestR << endl;
    	cout << "The lowest amount of rainfall is " << lowestR << endl;
    	cout << "The average temperature was " << totalTemp << endl;
    	cout << "The lowest temperature was " << lowestTemp << endl;
    	cout << "The highest temperature was" <<highestTemp << endl;
    	getchar();
    
    	std::cin.clear();
    	std::cin.ignore(std::cin.rdbuf()->in_avail());
    	std::cin.get();
    
    	return 0;
    }
    
    double sumArrayR (double array [], int size) // und hier mit KLEINEM S geschrieben
    {
    	double totalR = 0;
    	for (int count = 0; count < size; count++)
    		totalR += array [count];
    
    	return totalR;
    }
    
    double gethighestR (double array [], int size)
    {
    	double highestR;
    	highestR = array [0];
    	for (int count = 1; count < size; count++)
    	{
    		if (array [count] > highestR)
    		highestR = array[count];
    	}
    
    	return highestR;
    }
    
    double getlowestR (double array[], int size)
    {
    	double lowestR;
    	lowestR = array [0];
    
    	for ( int count = 1; count < size; count++)
    	{
    		if (array[count] < lowestR)
    			lowestR = array[count];
    	}
    
    	return lowestR;
    }
    
    double gethighestTemp (double array [], int size)
    {
    	double highestTemp;
    	highestTemp = array [0];
    	for (int count = 1; count < size; count++)
    	{
    		if (array [count] > highestTemp)
    		highestTemp= array [count];
    	}
    
    	return highestTemp;
    }
    
    double getlowestTemp (double array [], int size)
    {
    	double lowestTemp;
    	lowestTemp = array [0];
    	for (int count = 1; count < size; count++)
    	{
    		if (array [count] < lowestTemp)
    		lowestTemp = array[count];
    	}
    
    	return lowestTemp;
    }
    

    Siehe eingefügte Kommentare, die Funktion muss schon mit gleichem Namen deklariert und definiert werden, Bezeichner sind in C++ case-sensitive.

    Bitte nächstes Mal die C++-Tags benutzen, dann bleibt auch die Einrückung erhalten:)



  • HI,
    vielen vielen Dank. Nächstes mal werde ich die Tags verwenden, wieder was dazu gelernt.
    Ich habe gleich noch eine frage: ich soll auch noch den Monat anzeigen in dem die hächste und niedrigste temperatur war. wie mach ich des?



  • U-Boot schrieb:

    Die Funktionen sind doch vor der main() deklariert, sieht man nur so schlecht 😛

    [...] die Funktion muss schon mit gleichem Namen deklariert und definiert werden, Bezeichner sind in C++ case-sensitive.

    Eben, sie wurde also nicht deklariert. :p

    Playmuckel schrieb:

    Ich habe gleich noch eine frage: ich soll auch noch den Monat anzeigen in dem die hächste und niedrigste temperatur war. wie mach ich des?

    Erkundige dich mal über std::min() und std::max() , zum Beispiel auf cplusplus.com.



  • Eben, sie wurde also nicht deklariert.

    Die Funktion, die er aufruft schon :p



  • Hallo,
    mein problem ist noch dass ich bei der average tem immer 0 angezeigt bekomme. Was mache ich falsch?

    // This programm calculates average temperature
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    struct temp
    {
        double temp [12];
        double rainfall [12]; 
    }; 
    double SumArrayR (double[], int);
    
    double gethighestR (double [], int);
    
    double getlowestR (double [], int);
    
    double gethighestTemp (double[], int);
    
    double getlowestTemp (double[], int);
    
    double SumArrayTemp (double[], int);
    
    int main ()
    {
        const int months = 12;
            double rainfall [months],
               temp [months],
               totalR,
               highestR,
               lowestR,
               averageR,
               totalTemp,
               highestTemp,
               lowestTemp,
               averageTemp;
        //Get the rainamount of every months
        cout << "Enter the amount of rain for every months.\n";
        for (int count = 0; count < months; count++)
        {
            cout << "Months" << (count +1) <<": ";
            cin >> rainfall [count];
            }
        // Get the temperature of every months
        cout << "Enter the average temperature of every months. \n";
        for (int count = 0; count < months; count++)
        {
            cout << "Months" << (count +1) <<": ";
            cin >> temp [count];
            }
            totalR = SumArrayR (rainfall, months);
    
            averageR = totalR/ months;
    
            highestR = gethighestR (rainfall, months);
    
            lowestR = getlowestR (rainfall, months);
    
            averageTemp = totalTemp/ months;
    
            highestTemp = gethighestTemp (temp, months);
    
            lowestTemp = getlowestTemp (temp, months);
    
              cout << fixed << showpoint << setprecision (2);
            cout << "The total amount of rainfall is " << totalR << endl;
            cout << "The average amount of rainfall per month is " << averageR << endl;
            cout << "The highest amount of rainfall is " << highestR << endl;
            cout << "The lowest amount of rainfall is " << lowestR << endl;
            cout << "The average temperature was " << averageTemp << endl;
            cout << "The lowest temperature was " << lowestTemp << endl;
            cout << "The highest temperature was " << highestTemp << endl;
            getchar();
    
       std::cin.clear();
        std::cin.ignore(std::cin.rdbuf()->in_avail());
        std::cin.get(); 
            return 0;
            }
            double SumArrayR (double array [], int size)
            {
                               double totalR = 0;
                   for (int count = 0; count < size; count++)
                   totalR += array [count];
                   return totalR;
                   }
    
            double gethighestR (double array [], int size)
            {
                   double highestR;
                   highestR = array [0];
                   for (int count = 1; count < size; count++)
                   {
                       if (array [count] > highestR)
                       highestR = array[count];
                       }
                       return highestR;
                       }
    
            double getlowestR (double array[], int size)
            {
                   double lowestR;
                   lowestR = array [0];
    
                   for ( int count = 1; count < size; count++)
                   {
                       if (array[count] < lowestR)
                       lowestR =  array[count];
                       }
                       return lowestR;
                       }
    
            double gethighestTemp (double array [], int size)
            {
                    double highestTemp;
                     highestTemp = array [0];
                     for (int count = 1; count < size; count++)
                     {
                         if (array [count] > highestTemp)
                     highestTemp= array [count];
                     }
                     return highestTemp;
                     }
            double getlowestTemp (double array [], int size)
            {
                 double lowestTemp;
                 lowestTemp = array [0];
                 for (int count = 1; count < size; count++)
                 {  
                     if (array [count] < lowestTemp)
                     lowestTemp = array[count];
                     }
                     return lowestTemp;
                     }
                double  SumArrayTemp (double array [], int size)
            {
                               double totalTemp = 0;
                   for (int count = 0; count < size; count++)
                   totalTemp += array [count];
                   return totalTemp;
                   }
    


  • Das heißt kombelürpar



  • Fehler gefunden. Aber trotzdem danke



  • Playmuckel schrieb:

    Fehler gefunden.

    Gut, das hätte dir so kaum jemand gemacht.

    Nur den relevanten Code zu posten könnte mehr Leute dazu animieren, dir zu helfen... 😉
    Oder bei solchen Dingen ist auch der Debugger eine gute Wahl.


Anmelden zum Antworten