reading from data file

i need my code to stop outputting all the numbers throughout the steps it is going through i just need it to output the total

this is my input
M
C
C
C
L
I
V

and its output is

Your total is 1000
Your total is 1100
Your total is 1200
Your total is 1300
your total is 1350
Your total is 1351

i just need it to output the last number

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  // write a program to read a string of characters
// that represent a Roman numberal and then convert
// to Arabic form ( an integer
// input from data file

	 
	#include <iostream> //keyboard I/O
	#include <fstream> //external file streams
	#include <conio.h> //getch()
	#define in_file "data.txt"
	using namespace std;
	 
	int main()
	{
	    ifstream ins; //ins as output stream
	     
	    //define variables
	    int total = 0,//total value of numbers
	        current = 0, //current character
	        previous = 5000; //previous character
	    char ch, //string to be read
	        M, D, C, L, X, I; //Roman numerals
	     
	    //open files
	    ins.open(in_file);
	     
	    while (!ins.eof())
	    {
	        ins.get(ch); //read ch from file
	                 
	        while (ch!='\n')
			{
	            switch (ch)
	            {
	                case 'M': current = 1000;
	                        break;
	                case 'D': current = 500;
	                        break;
	                case 'C': current = 100;
	                        break;
	                case 'L': current = 50;
	                        break;
	                case 'X': current = 10;
	                        break;
	                case 'V': current = 5;
	                        break;
	                case 'I': current = 1;
	                        break;
	            } //end switch statement
	         
	            if (previous >= current)
	                total += current;
	            else
	                total = total - (2*previous) + current;
	 
	            previous = current;
	            ins.get(ch);
	             
	        } //end inner while loop
	        cout << endl;
	        cout << " Your total is " << total << endl;


	    } //end outer while loop
	
	ins.close();
	getch();
}
Topic archived. No new replies allowed.