Hello guys,

I am new in this forum and i hope im gonna get some fast help.

I have this problem where i should input numbers from a .doc file, and the program should output how many times the number of occurences of each number.

ie: the numbers in the .doc file are 2,3,6,8,9,2,1,1,3,1.

The program should read the numbers from the file and outputs the following:
Number 1 = 3
Number 2 = 1 ... and so on.

I started with the following but im getting stuck.
Any help please??

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;


int main()
{
int array[10000];
ifstream numbers( "numbers.doc", ios::in);
if(!numbers)
{
cerr << endl << "File could not be opened" << endl;
system("pause");
exit(1);
}


for (i=0, i<10000, i++)
array = 0;     //initializes array


for (i=0, i<50, i++)
{
if (i=1)
array[n] += array;
cout << array;
}
{
if (i=2)
array[n] += array;
cout << array;
}
///and so on.

I appreciate any suggestions and assistance,

Thank u

Edited 3 Years Ago by pritaeas: Fixed formatting

Site rules, "CODE TAGS!"

The usual structure I suggest often, to avoid the whole emergency bail out thing.

file open
if(file.is_open())
{
  do stuff here;

  file.close();
}
else
{
   cout << "Error!";
}

You probably should place those loops in a function too.
Where is i declared?

You need to format it and place it in code tags, I got lost, and was sure I saw something funky with the brackets after the second for loop.

This article has been dead for over six months. Start a new discussion instead.