Hi, im new here and also new to C++ (pretty much new to programming anyways)

I have been working in an assignment and got stuck trying to store information into a 3x3 array, and then retrieving the data.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
   
   float num[3][3];

   cout << "Enter 9 numbers: ";
   for (int i = 0; i < 9; i++)
   {
		cin >> num[3][3];
   }
   cout << num [4]; 
}

the program runs fine and accepts the input of 9 digits, however when trying to display some of the data it just gives a weird code composed of numbers and letters, I'm trying to store the data and then use it for other operations but cant go further without making sure that the data is correctly added to the array. (the array must be 3x3 according to my assignment)

Recommended Answers

All 2 Replies

float num[3][3];

   std::cout << "Enter 9 numbers: ";

   for (int i = 0; i < 3; ++i )
      for( int j = 0 ; j < 3 ; ++j )
	 std::cin >> num[i][j];

   for (int i = 0; i < 3; ++i )
   {
      for( int j = 0 ; j < 3 ; ++j ) std::cout << num[i][j] << ' ' ;
      std::cout << '\n' ;
   }

See: http://www.cplusplus.com/doc/tutorial/arrays/

wow thanks, that was fast, now i can recall any piece of data from the array with ease, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.