#can anybody explain whats wrong ?

8 messages · Page 1 of 1 (latest)

polar laurel
#

my code :
#include <iostream>
using namespace std;
int main()
{
int a;
long b;
char c;
float d;

double f;
cin>>a>>b>>c>>d>>f;
cout<<a<<endl<<b<<endl<<c<<endl<<d<<endl<<f;
return 0;

}
the problem : Input Format

Input consists of the following space-separated values: int, long, char, float, and double, respectively.

Output Format

Print each element on a new line in the same order it was received as input. Note that the floating point value should be correct up to 3 decimal places and the double to 9 decimal places.
it says wrong on test 2,3,4 ?

wicked light
#

also you're not printing to the correct decimal places

subtle sigil
#

Formatting:

#

;compile

#include <iostream>
using namespace std;
int main()
{
    int a;
    long b;
    char c;
    float d;

    double f;
    cin>>a>>b>>c>>d>>f;
    cout<<a<<endl<<b<<endl<<c<<endl<<d<<endl<<f;
    return 0;
} 
spring quiverBOT
#
Program Output
0
0

0
0
subtle sigil
#

I'd also suggest avoiding the use of using namespace std

mortal oysterBOT
#
Why Is `using namespace std` Considered Bad Practice?

using namespace std will import all the symbols from std into the enclosing namespace. This can easily lead to name collisions, as the standard library is filled with common names: get, count, map, array, etc.

A key concern with using namespace std; is not what is imported now but rather what may suddenly be imported in the future.

While using namespace std; is alright for tiny projects, it is important to move away from it as soon as possible. Consider less intrusive alternatives:

// OK: *only* import std::vector
using std::vector;
// OK: namespace alias
namespace chr = std::chrono;
chr::duration x;