Entering A Decimal

I'm writing a code that requires the user to enter a decimal as an int value, but when I have gone through to test it, the program freaks out and goes ballistic unless you enter in a non-decimal number.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int stockinvest;

cout<<"Please enter the number of stocks you would like to buy: "<<endl<<endl<<endl;
cin>>stockinvest; 


int shareprice;

cout<<"Please enter the dollar price of chosen stock: "<<endl<<endl;
cin>>shareprice;

cout<<"You have purchased "<<stockinvest<<" at "<<shareprice<<" for a total of: $"<<stockinvest * shareprice<<endl;



        cout<<main()<<endl;
    }


basically, cin<<shareprice; needs to be able to be a decimal. I'm pretty sure it has to do with float, but I couldn't find anything that answered this specific question.
An int can't be a decimal. Try using a float instead.
Last edited on
I figured it was something simple like that, much appreciated!
Topic archived. No new replies allowed.