Brauche dringed Hilfe



  • Hallo Leute ich versuche jetzt ein Programm mit c++ zu schreiben welches nach vor und nachmae fragt und danach soll der Benutzer Klausur Noten ,Referat Noten und 8 Übungsaufgaben Noten eingeben und dannach den Notendurchshnitt berechnen .. mein Problem liegt bei der Eingabe von den 8 Noten ..
    DAS IST MEIN PROGRAMM

    #include<iostream>
    #include<vector>
    #include<string>
    using namespace std ;
    void main ()
    {
    char name ; // der compiler akziptiert keine string vraiable warum ?

    float refratnote,klausurnote ;
    vector <float> uebungsnote ;
    cout<<"Nachname,Vorname eingeben ... \n" ;
    cin>> name ;
    cout <<"Klausurnote eingeben :- \n" ;
    cin>> klausurnote ;
    cout <<"Refratnote eingeben :- \n" ;
    cin >> refratnote ;
    int i ;
    for (i=1;i<9;++i)
    cout<<"Die Note von der Uebungsaufgabe Nr." << i << " eigeben \n" ; // ich will jetzt die 8 noten eingeben der compiler zeigt den vorherigen Satz 8 Mal hinter einander !! Kann jemand mir bei dem Punkt helfen ??

    }

    DANKE IM VORAUS
    A.



  • Hmmm okayyy 🙄

    Ich nehme mich der Sache einmal an. Codetags + Formatierung:

    #include<iostream> 
    #include<vector> 
    #include<string> 
    using namespace std ; 
    
    void main () 
    { 
        char name ; // der compiler akziptiert keine string vraiable warum ? 
        float refratnote,klausurnote ; 
        vector <float> uebungsnote ; 
        cout<<"Nachname,Vorname eingeben ... \n" ; 
        cin>> name ; 
        cout <<"Klausurnote eingeben :- \n" ; 
        cin>> klausurnote ; 
        cout <<"Refratnote eingeben :- \n" ; 
        cin >> refratnote ; 
        int i ; 
        for (i=1;i<9;++i) 
            cout<<"Die Note von der Uebungsaufgabe Nr." << i << " eigeben \n" ; // ich will jetzt die 8 noten eingeben der compiler zeigt den vorherigen Satz 8 Mal hinter einander !! Kann jemand mir bei dem Punkt helfen ?? 
    }
    

    So, und nun einige Kommentare zum Quellcode.

    1. void main() gibt es nicht; benutze int main() .
    2. char ist nur ein einzelnes Zeichen, du musst schon einen std::string benutzen. Der Compiler, wenn er denn taugt, wird dies akzeptieren. Einlesen kannst du Zeilenweise mit getline .

    .. mein Problem liegt bei der Eingabe von den 8 Noten ..

    Was ist dein Problem? Du musst für die Eingabe auch eine for -Schleife bauen und bei jeder Iteration die beiden Noten im vector speichern. Nur so kannst du am Ende wieder alle ausgeben...

    BTW, falsches Forum...

    MfG



  • Ausserdem ist es das falsche Forum.
    C++ wäre korrekt.

    Simon



  • Dieser Thread wurde von Moderator/in Jochen Kalmbach aus dem Forum C++/CLI mit .NET in das Forum C++ verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • Hallo

    1. void main() gibt es nicht; benutze int main().

    Das nach dem Semikolon ist OK, dass da hinter nicht ganz. Es gibt es schon, nur ist es auf eine gewisse Weise illegal.

    5.1.2.2.1 Program startup
    The function called at program startup is named main. The implementation declares no
    prototype for this function. It shall be defined with a return type of int and with no
    parameters:
    int main(void) { /* ... */ }
    or with two parameters (referred to here as argc and argv, though any names may be
    used, as they are local to the function in which they are declared):
    int main(int argc, char *argv[]) { /* ... */ }
    or equivalent;8) or in some other implementation-defined manner.
    If they are declared, the parameters to the main function shall obey the following
    constraints:
    — The value of argc shall be nonnegative.
    — argv[argc] shall be a null pointer.
    — If the value of argc is greater than zero, the array members argv[0] through
    argv[argc-1] inclusive shall contain pointers to strings, which are given
    implementation-defined values by the host environment prior to program startup. The
    intent is to supply to the program information determined prior to program startup
    from elsewhere in the hosted environment. If the host environment is not capable of
    supplying strings with letters in both uppercase and lowercase, the implementation
    shall ensure that the strings are received in lowercase.
    — If the value of argc is greater than zero, the string pointed to by argv[0]
    represents the program name; argv[0][0] shall be the null character if the
    program name is not available from the host environment. If the value of argc is
    greater than one, the strings pointed to by argv[1] through argv[argc-1]
    represent the program parameters.
    — The parameters argc and argv and the strings pointed to by the argv array shall
    be modifiable by the program, and retain their last-stored values between program
    startup and program termination.

    Mfg.
    way


Anmelden zum Antworten