writing and reading

im having this problem on reading the input. i have this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	ifstream inFile;

	int length, width, area;

	inFile.open("dime.txt");
	cout << "reading dimensions of 5 rectangles from the file\n";

	// process rectangle 1

	inFile >> width;
	inFile >> length;
	area = width * length ;
	cout << "Area of rectangle 1: " << area << endl;

	

	// close the file
	
	inFile.close();
		cout<< " im closing the file\n";
	return 0;
}

and the dime.txt is 10 2. i suppose to get 20 but im getting weird #'s
Last edited on
Would you mind editing your post and putting the source inside code tags? It will make it a lot more legible and folks here will be more likely to look at it.
Could you be more descriptive? What numbers are you getting?
your code looks fine (from what I can see) I'm wondering if it's a problem with your text file. You say it has 10 2, do you have any extra characters. Also, even though you're instreaming your variables I would still initialize them. Bad practice not to.

Lol and your output is wrong, it says your reading dimensions of 5 rectangles... looks like one =)
the note pad online had these 2 #[10 2]. i thing the problem is in visual basic because isntead i did the multiplication of width and length, i online wrote length and i got a huge negative #.

yes i was suppose to do the area of five triangles since i got that problem im trying to solve just one instead.
Topic archived. No new replies allowed.