How to declare the array and read the array? Must I use data structure?

Two array

1 30
2 20
3 10
4 50
5 15

yes...but it was so complicated..i want to read as simple as possible.

I'm having problem when i want to cout the data that i sort.

int temp,bubsort,arr,display;
	if (myfile.is_open())
	{
		for (int i = 0; i < exams.size(); i++) 
		{
			for (int j = 0; j<exams.at(i).total.size(); j++) 
			{
		cout<<"\n"<<i+1<<":"<<" "<< exams[i].total[j]<<"\t"; // output list of exam codes for this student
	  
	if (exams[i+1].total[j+1]>exams[i].total[j])
	
	{	
		temp=exams[i+1].total[j+1];
		exams[i+1].total[j+1]=exams[i].total[j];
		exams[i].total[j]=temp;	

	}
	bubsort(arr,j);
	display(arr,j);
	cout<<endl<<endl;

	}		
	}	
	}
cin.get();
return 0;
}
}

you should know by now how to open and read the file. All you have to do is make a 2d array of integers int array[255][2] = {0}; That will hold up to 255 rows of data

.......it's not hard at all.

(edit: lol a little late, sorry I was reading the other thread)

Just change it like this to make 2d array?

int array[140][2]={0};
int temp;
if (myfile.is_open())
{
for (int i = 0; i < exams.size(); i++) 
{
for (int j = 0; j<exams.at(i).total.size(); j++) 
{
cout<<"\n"<<i+1<<":"<<" "<< exams[i].total[j]<<"\t"; // output list of exam codes for this student
if (exams[i+1].total[j+1]>exams[i].total[j])
{	
temp=exams[i+1].total[j+1];
exams[i+1].total[j+1]=exams[i].total[j];
exams[i].total[j]=temp;	
}

>>Just change it like this to make 2d array?
NO NO.

int main()
{
    int array[140][2] = {0};
    ifstream myfile("filename.txt");
    int i = 0;
    while( myfile >> array[i][0] >> array[i][1] )
           i++;
    myfile.close();
}

Why no output is appear?

#include <iostream>   // std::cout
#include <fstream>
#include <iomanip>
#include <string>    // std::string
#include <vector>    // std::vector<>
#include <algorithm> //std::for each()
#include <iostream>   // std::cout
#include <fstream>
#include <iomanip>
#include <string>    // std::string
#include <vector>    // std::vector<>
#include <algorithm> //std::for ea


using namespace std; // import "std" namespace into global namespace

int main()
{
    int array[140][2] = {0};
    ifstream myfile("STA83SOLUTION.txt");
    int i;
    while( myfile >> array[i][0] >> array[i][1] )
           i++;

{
	ofstream myfile;
	myfile.open("411.txt");
    myfile.close();
}

	if (myfile.is_open())
	{
		for (int i = 0; i < array[i][0]; i++) 
		{
			for (int j = 0; j<array[i][0]; j++) 
			{
		cout<<"\n"<<i+1<<":"<<" "<< array[i][0]<<"\t"; // output list of exam codes for this student
			}
		}
	}
}

F:\508.cpp(35) : warning C4508: 'main' : function should return a value; 'void' return type assumed

>>Why no output is appear
Think about what you are doing. Look at lines 30 and 35. Can you guess the value of array[0] on the first iteration of that loop ? Hint: see line 19.

F:\508.cpp(35) : warning C4508: 'main' : function should return a value; 'void' return type assumed

add return 0; at the end of main()

So I must chane [0] to [140][2]?

int array[140][2] = {0};
    ifstream myfile("STA83SOLUTION.txt");
    int i;
    while( myfile >> array[i][0] >> array[i][1] )
           i++;

{
	ofstream myfile;
	myfile.open("508.txt");
    myfile.close();
}

	if (myfile.is_open())
	{
		for (int i = 0; i < array[140][2]; i++) 
		{
			for (int j = 0; j<array[140][2]; j++) 
			{
		cout<<"\n"<<i+1<<":"<<" "<< array[i][2]<<"\t"; // output list of exam codes for this student
			}
		}
	}return 0;

>>So I must chane [0] to [140][2]?

No. Just forget it. You have no clue what you are doing.

so..I must continue this programming or continue the old one?

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.