vendredi 11 août 2023

The following program is to print each element on a new line in the same order it was received as input [closed]

In this programming question, I have been provided with different data types namely int, long, char, float, and double as input and I am supposed to print each element on a new line in the same order it was received as input.

Sample Input:

3 12345678912345 a 334.23 14049.30493

Sample Output:

3
12345678912345
a
334.230
14049.304930000

My program:

#include <iostream>
using namespace std;

int main(){

   int val1{};
  long int val2{};
  char val3{};
  float val4{};
  double val5{};

  cin>> val1>>val2>>val3>>val4>>val5;

 cout << val1<<endl;
 cout << val2<<endl;
 cout << val3<<endl;
 cout << val4<<endl;
 cout << val5<<endl;

  return 0;
}

The Output:

3
12345678912345
3
2147483647

0
0

==== Program exited with exit code: 0 ====
Time elapsed: 000:24.203 (MM:SS.MS)
Press any key to continue...`

Please elaborate the mistake as I am a beginner at C++.

Aucun commentaire:

Enregistrer un commentaire