The following program worked already before I added line 12, the line reading: " std::cout<<" Natürlicher Logarithmus von ";std::cin>>X; ".
Now I get a lot of errors (see below)!
Please Help
// Berechnung des natürlichen Logarithmus (Grenzwert nach Hurwitz)
#include <iostream>
#include <cmath>
#include <iomanip>
double h{1.0},Result,oldResult,Limit{1.0e-8},X{2.0},Inkr;
int c{0}, prez;
int main()
std::cout<<" Natürlicher Logarithmus von ";std::cin>>X;
std::cout<<" Genauigkeit (Zehnerpotenz): ";
std::cin>>prez; prez=std::abs(prez);
Limit=std::pow(10,-prez-1);
Result=((std::pow(X,h))-1)/h;
do
{
oldResult=Result;
h=h/2.0;
Result=((std::pow(X,h))-1)/h;
Inkr=std::abs(oldResult-Result);
++c;
}
while (Inkr>Limit);
Result=std::round(Result*std::pow(10,prez))*std::pow(10,-prez);
std::cout<<std::setw(prez+3)<<std::setprecision(prez)<<std::fixed<<Result<<" \t"<<c<<'\n';
return(0);
}
Logarithmun.cpp:12:5: error: expected initializer before 'std' 12 | std::cout<<" Nat├╝rlicher Logarithmus von ";std::cin>>X; | ^~~ Logarithmun.cpp:12:53: error: 'cin' in namespace 'std' does not name a type 12 | std::cout<<" Nat├╝rlicher Logarithmus von ";std::cin>>X; | ^~~ In file included from Logarithmun.cpp:3: C:/msys64/mingw64/include/c++/12.2.0/iostream:60:18: note: 'std::cin' declared here 60 | extern istream cin; /// Linked to standard input | ^~~ Logarithmun.cpp:13:10: error: 'cout' in namespace 'std' does not name a type 13 | std::cout<<" Genauigkeit (Zehnerpotenz): "; | ^~~~ C:/msys64/mingw64/include/c++/12.2.0/iostream:61:18: note: 'std::cout' declared here 61 | extern ostream cout; /// Linked to standard output | ^~~~ Logarithmun.cpp:14:10: error: 'cin' in namespace 'std' does not name a type 14 | std::cin>>prez; prez=std::abs(prez); | ^~~ C:/msys64/mingw64/include/c++/12.2.0/iostream:60:18: note: 'std::cin' declared here 60 | extern istream cin; /// Linked to standard input | ^~~ Logarithmun.cpp:14:21: error: 'prez' does not name a type 14 | std::cin>>prez; prez=std::abs(prez); | ^~~~ Logarithmun.cpp:15:5: error: 'Limit' does not name a type 15 | Limit=std::pow(10,-prez-1); | ^~~~~ Logarithmun.cpp:16:5: error: 'Result' does not name a type 16 | Result=((std::pow(X,h))-1)/h; | ^~~~~~ Logarithmun.cpp:18:5: error: expected unqualified-id before 'do' 18 | do | ^~ Logarithmun.cpp:26:5: error: expected unqualified-id before 'while' 26 | while (Inkr>Limit); | ^~~~~ Logarithmun.cpp:28:5: error: 'Result' does not name a type 28 | Result=std::round(Result*std::pow(10,prez))*std::pow(10,-prez); | ^~~~~~ Logarithmun.cpp:29:10: error: 'cout' in namespace 'std' does not name a type 29 | std::cout<<std::setw(prez+3)<<std::setprecision(prez)<<std::fixed<<Result<<" \t"<<c<<'\n'; | ^~~~ C:/msys64/mingw64/include/c++/12.2.0/iostream:61:18: note: 'std::cout' declared here 61 | extern ostream cout; /// Linked to standard output | ^~~~ Logarithmun.cpp:31:5: error: expected unqualified-id before 'return' 31 | return(0); | ^~~~~~ Logarithmun.cpp:32:1: error: expected declaration before '}' token 32 | } | ^
I did remove line 12, but the errors remain.
So I obviously changed inadvertently something fundamental but I cannot find the problem. I do not understand the error at all! I used similar code a lot already.