Formula Generator

I am writing a program that solves solution to acid ratio story problems. For example: If there is 10 liters of a 25 % acid solution, how many liters of water do you need to add to make it a 10 % acid solution. My problem is that I'm getting weird outputs for my answers.
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
#include <iostream>
using namespace std;

int main()
{
int solution;
int acidpercent;
int acidwanted;
int acidpart;
int answer;

cout<<"SolutionGen"<<endl;
cout<<"____________________"<<endl<<endl;

cout<<"Solution:";
cin>>solution;
cout<<endl;

cout<<"Acid Percent:";
cin>>acidpercent;
acidpercent/100;
cout<<endl;

cout<<"Acid Percent to Attain:";
cin>>acidwanted;
acidwanted/100;
cout<<endl;

solution * acidpercent == acidpart;
acidpart * 100 / acidwanted == answer;
cout<<"Need to add ";
cout<<answer - solution;
cout<<" to get "<<acidwanted<<"."<<endl;


system("pause>nul");
	return 0;
}


Thanks
Hi there,

I think you may want to use doubles instead of ints. Integers, when divided by say 100, will still be an int, so if you do say 27/100 you'll get 0. This would seem to be a large target for your errors.

Also, lines like:

acidpercent/100

Don't really do anything. You're not storing the results of any of your calculations. You need to put them into either a new vairable, or reuse them.

==

is an equality operator, that returns a boolean. Probably not what you want here.

Hope this helps.
Last edited on
Thanks,
I think I the have codding errors fixed but I need to change what I'm actually telling the computer to do.
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
#include <iostream>
using namespace std;

int main()
{
double solution;
double acidpercent;
double acidwanted;
double acidpart;
double answer;

cout<<"SolutionGen"<<endl;
cout<<"____________________"<<endl<<endl;

cout<<"Solution:";
cin>>solution;
cout<<endl;

cout<<"Acid Percent:";
cin>>acidpercent;
acidpercent = acidpercent /100;
cout<<endl;


cout<<"Acid Percent to Attain:";
cin>>acidwanted;
acidwanted = acidwanted /100;
cout<<endl;

acidpart = solution * acidpercent ;
answer = acidpart * 100 / acidwanted ;
cout<<"Need to add :";
cout<<answer - solution;


system("pause>nul");
	return 0;
}
Topic archived. No new replies allowed.