strange problem in saving in note

hi all
this is my program
why when result of 'dar' Variable saves in 'far' note something plus will be save with result for example when the result is 100 another number will be save like this 8.40779e-045 why?
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 #include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
void output(float[],int);
int main()
{
	int farvardin[31],ordibehesht[31],khordad[31],tir[31],mordad[31],shahrivar[31],
	mehr[30],aban[30],azar[30],dey[30],bahman[30],esfand[29];
	
	float far[16],ord[16],khor[16],ti[16],mor[16],shahr[16],
	meh[15],aba[15],aza[15],de[15],ba[15],esf[14],dar,s,z;
	
	ofstream list("list.txt",ios::app);
	ofstream sal("sal.txt",ios::app);
	ofstream farv("far.txt",ios::app);
	
	string name;
	int tedad,gheymatye,newadd,i=0,gheymateto,co=0,di;
	cout<<"Enter '1' For Working with Stocks:"<<endl;
	cout<<"Enter '2' For Show The List:"<<endl;
	cin>>di;
	switch(di){
		case 1:
	cout<<"Enter '1' For Adding:"<<endl;
	cout<<"Enter '2' For Accounting:"<<endl;
	cin>>newadd;
	switch(newadd){
	case 1:
	//New Adding---------------------------------------------------------------------------//
	cout<<"Enter your Stock Name:"<<endl;
	cin>>name;
	cout<<"Enter your Amount of stock:"<<endl;
	cin>>tedad;
	list<<name<<' '<<tedad<<"   ";
	cout<<endl;
	break;
	//end of Adding------------------------------------------------------------------------//
	case 2:
	//being of process--------------------------------------------------------------------//
	string na; int ted;
	cout<<"Enter your Stock Name For Accounting:";
    cin>>na;
    ifstream list;
    list.open("list.txt");
    bool found = false;
    while (list>>name>>tedad)
    {
        if(na==name)
        {
        	cout<<"Enter Your Yesterday Price:"<<endl;
            cin>>gheymatye;
            s=gheymatye*tedad;
            cout<<"Enter Your Today Price:"<<endl;
            cin>>gheymateto;
            z=gheymateto*tedad;
           found = true;
        }
    }
    if (!found)
    {
       cout<<"Error Stock Name was not found!";
       break;
    }
    farvardin[i]=s;
    i++;
    farvardin[i]=z;
	for(int k=0;k<=i;k++){
	sal<<farvardin[k]<<endl;
    }
	s*=100;
    dar=(s/z);  
    dar-=100;
	cout<<"%"<<dar; 
    far[co]=dar;
    for(int j=0;j<=i;j++)
    farv<<far[j]<<endl;
    break;
}
}
}
Not looked at it in great detail, but here's a hint of what might be wrong:


(54): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
(57): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
(66): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
(68): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data


So in various parts of your program you're trying to squeeze floats into ints.
That's not good, but not sure it's your issue.
another number will be save like this 8.40779e-045 why?

it's hard to tell from the above code, it's not easy to read.

However a value such as 8.40779e-045 typically would be caused by one of three reasons:

1. uninitialised variable. A variable will contain garbage until something is actually assigned to it.

2. reading from an array element beyond the boundary of the array.

3. data corruption. For example if something is stored in an element beyond the boundary of an array it will over-write some adjacent areas of memory, with undefined (but bad) results. An error occurring earlier may not be obvious at the time, but can affect something else seemingly unrelated later on.
my program works fine until line 75 is there any problem after line 75 ??
What are the values of co and i when execution reaches line 75? it may be that there is out-of-bounds array access.

Also as i mentioned earlier, out of bounds array access earlier in the program can cause unexpected errors later.
my program works fine until line 75 is there any problem after line 75 ??
far is completely uninitalize except for the first value since co is always 0.
Topic archived. No new replies allowed.