Hey, im about to learn C++ : D
Now i am in the Chapter where i learn about cin...
(Yea i am not that far atm^^)
So i did everything exactly like it is written in the book:
So it works kinda fine yea
Would be nice if you would correct any faults.
My Problem is: I dont entirly get the If statement would be nice if you would explain it to me... and my second problem is:
"It now shows please insert a floutnumber: "
if u wirte anything else then a number it says: "Wrong Input" thats fine...
But if i write 5.5 for example it jumps to the next line but does nothing.
Then if i write it again it gives the wished "Input was: " + Variable Wert.
But why do i have to enter it 2 times????
I dont got it please help^^
Now i am in the Chapter where i learn about cin...
(Yea i am not that far atm^^)
So i did everything exactly like it is written in the book:
Code:
// cin1.cpp // Filename
#include <iostream> //including the dll? Biblothek? iostream
using namespace std; /* The following content uses The Namespace std, else we would have to wirte std::cout everytime */
int main(void) { /*Main Function, which has to be a number (int=integer) (i forgot what void meant would be nice if someone could explain it fast) */
float wert; /* defines the Variable wert as a float (means a number with decimal point) */
cout << "Bitte eine Fließkommazahl eingeben : "; /*writes the Text between the "*" out and then rests there */
cin >> wert; /* now it waits there for an input with cin for the variable of wert. It already checked that wert has to be a float or it will error */
if (!(cin >> wert)) { /*New If stance where it checks something would be nice if you would explain it to me i dont entirly got it */
cerr << "Fehler bei der Eingabe!\n"; /* it checked if cin is a float or not (whats the matter with the "!" ?? what does "cin >> wert" do?
So atm it works if i wirte something else then a floatnumber it says : "Fehler bei der Eingabe!" Which means something like: "Wrong Input". So it checks if its a floutnumber and if not it says yo its wrong buddy*/
}
else { /* else statement beginnning */
cout << "Die Eingabe war " << wert << "\n"; /* Gives out: "Die Eingabe war " which means something like: "Input was: ", if it is a floatnumber (was checked in IF statement). And after that it gives out the variable: "wert" which must be a floatnumber at this point. */
}
return 0; /*Ends the Process */
}
Would be nice if you would correct any faults.
My Problem is: I dont entirly get the If statement would be nice if you would explain it to me... and my second problem is:
"It now shows please insert a floutnumber: "
if u wirte anything else then a number it says: "Wrong Input" thats fine...
But if i write 5.5 for example it jumps to the next line but does nothing.
Then if i write it again it gives the wished "Input was: " + Variable Wert.
But why do i have to enter it 2 times????
I dont got it please help^^