Dec 13, 2012 at 12:47pm UTC
so im really new to coding and have made a very simple program but i get this when i run it "5.9878e-039" this is my code
#include <iostream>
using namespace std;
int main()
{
float a;
float b;
float c;
float car[3];
cout << "enter number 1" << endl;
cin >> a;
a = car[0];
cout << "enter number 2" << endl;
cin >> b;
b= car[1];
cout << "enter number 3" << endl;
cin >> c;
c = car[2];
cout << car[3];
return 0;
}
Many thanks :D
Dec 13, 2012 at 12:49pm UTC
you dont have any values saved in car.
so when you run this
a=car[0];
b=car[1];
c=car[2];
a,b,c get some "random" number
car[3] doesn't exist in a 3element array
Last edited on Dec 13, 2012 at 12:50pm UTC
Dec 13, 2012 at 12:54pm UTC
I dont understand how they dont get values if i input a value to a,b,c with cin.
Dec 13, 2012 at 12:58pm UTC
a = car[0];
This will assign the value of car[0] (uninitialized) to a. If you want car[0] to get the value of a you will have to write it the other way.
car[0] = a;
If you don't need a, b and c for anything else you can remove them and use the array elements with cin directly.
cin >> car[0];
Last edited on Dec 13, 2012 at 1:00pm UTC
Dec 13, 2012 at 1:50pm UTC
Ah thanks, i got it know :D
Dec 13, 2012 at 1:51pm UTC
And do not forget, you declare an array with 3 positions, but the array starts 0 position, then you can only use the positions: 0, 1, 2 .
GGarciaBas