(Super Beginner) Need help multiplying to get percentage
Sep 17, 2016 at 4:43pm UTC
I can't get my code to show a percent when I divide my percent/100 it just shows 0 when ran. I am extremely new to this but am enjoying the learning experience and would appreciate any help, thanks!
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
#include <iostream>
using namespace std;
int main()
{
int number_of_shares, share_price,percent;
double x=100;
cout << "How many shares did you buy?\n" ;
cin >> number_of_shares;
cout << "\n" ;
cout << "How much is each share?\n" ;
cin >> share_price;
cout << "\n" ;
cout << "What is the commission charged?\n" ;
cin >> percent;
cout << "Stock Cost:" ;
cout << number_of_shares*share_price;
cout << "\n" ;
cout << "\n" ;
cout << "Commission Charged: \n" ;
cout << (number_of_shares*share_price) - (number_of_shares*share_price)*(percent/100);
cout << "\n" ;
cout << (percent/100);
return 0;
}
Sep 17, 2016 at 5:05pm UTC
Int's will only show whole numbers, so percent needs to be a double.
Topic archived. No new replies allowed.