Something is wrong with my titration calculator

Hello, I am making a simple titrations calculator. Here is what I have so far (Yes, yes, please don't berate me about system ("cls);)

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#include <iostream>
#include <cmath>  /// Headers used by C++ compilers
#include <cstdlib>
#include <stdio.h>


    double acidvol;
    double acidconc;
    double basevol;
    double acidmol;   ///Declarations for the variables used in this program.
    double baseconc;
    double basemol;
    using namespace std;
    int main()

{  /// Main body

    titrations:
    cout << "Titrations calculator V 0.1";
    cout << "\n";
    cout << "This program assumes that units of volume are in dm^3";
    cout << "\n";
    cout << "\n";
    cout << "What was the concentration of the acid you used? (mol/dm^3): ";
    cin >> acidconc;
    cout << "\n";
    cout << "What was the volume of acid used? (dm^3): ";
    cin >> acidvol;

    acidmol = acidconc * acidvol;

    cout << "\n";
    cout << "What volume of your base was used? (dm^3): ";
    cin >> basevol;

    acidmol = basemol;

    baseconc = basemol / basevol;

    cout << "\n";
    cout << "One mol of the acid reacts with one mol of the base, so...";

    cout << "\n";
    cout << "\n";

    cout << "Strength of acid is: " << acidmol << " moles";

    cout << "\n";
    cout << "\n";
    cout << "The concentration of your base is: " << baseconc << " moles/dm^3";
    cout << "\n";
    cout << "\n";
    cout << "Press enter to continue";
    getchar();
    getchar();
    system ("cls");

goto titrations;
}


The problem is that the values for the conc of the base and the str of the acid don't calculate- I always end up with 0.

Have I made a dumb mistake?
On line 37 you assign acidmol the value of basemol, discarding the previously calculated value of acidmol for the junk in the uninitialized variable basemol.

Then you do some calculations with the junk in the uninitialized variable basemol.

edit: Oops. Since basemol is a global variable, it was initialized to 0.
Last edited on
Ahah, thank you!
I changed it to
37: basemol = acidmol;

and now itjustwerks. Thank you very much!
Topic archived. No new replies allowed.