[code]
double a;
double b;
double c;
a = 300;
b = 290;
c = a - b;
double d;
double e;
d = c / a;
e = d * 100
[code]
Yes i'm newish to c++ and don't link me to any tutorials on c++. I will start from the beginning to end of the tutorial on this website, but I'd like to finish this program I'm working on first.
When I use this code, e always ends up as 100, because its multiplied by 100. The program is giving e an value of 1, but its supposed to be what ever c / a equals.
#include <iostream>
usingnamespace std;
int main()
{
double a;
double b;
double c;
a = 300;
b = 290;
c = a - b;
cout<<c<<endl;
double d;
double e;
d = c / a;
e = d * 100;
cout<<"e = "<<e<<endl;
return 0;
}
Alright I figured out whats going wrong with my code, but I don't know how to fix it. Alright with the code you gave me with gp / sales. You have 10 / 300 an you should get 0.33 repeating. Though with my code instead of getting 0.33 the program just gets one as a default. I think this is because 300 won't go into 10. I think it could have something to do with having it as a 'double' variable. I'm not too keen on what the others are. I just know 'double and int'.
#include <iostream>
using namespace std;
int main()
{
double sls;
double cog;
cin>>sls>>cog;
double gp;
gp = sls - cog;
double gm;
gm = gp / sls; // This is where the code messes up /*
double gm2;
gm2 = gm * 100;
cout<<"gm2 = "<<gm2<<endl;
return 0;
}