How to input and output numbers into float array in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	const int TOTAL = 3;
	float arr[TOTAL];

	cout << "Enter 3 float numbers:" << endl;
	for (int i = 0; i < TOTAL; i++)
		cin >> arr[i];

	for (int i = 0; i < TOTAL; ++i)
		cout << arr[i] << ' ';

	cout << endl;
	
	return 0;
}

/*
run:

Enter 3 float numbers:
3.14
9.2
1.79
3.14 9.2 1.79

*/

 



answered May 3, 2018 by avibootz

Related questions

1 answer 127 views
1 answer 152 views
1 answer 155 views
1 answer 189 views
1 answer 631 views
1 answer 260 views
...