Division issues

I'm brand new to C++, and am trying to write a program that solves the equation Q=MC∆T. It's not finished as I still need to write the code to solve for C and for T, but there is a problem with the division used to solve for "M". The program works fine when trying to solve for "Q", but returns ridiculously high numbers when trying to find "M". I've looked around trying to find a solution with no luck, and I was wondering if someone could look over my code and help me out.

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
62
63
#include <iostream>

int solveQ(int M, int C, int T1, int T2);
int solveM(int Q, int C , int T1, int T2, int T);

int main()
{
    int choice;
    int Q;
    int M;
    int C;
    int T1;
    int T2;
    int T;

    std::cout << "What are you trying to solve for? press (1) for Q, (2) for M, or (3) for C? ";
    std::cin >> choice;

    if (choice == 1)
        {
            std::cout << "Enter M: ";
            std::cin >> M;
            std::cout << "Enter C: ";
            std::cin >> C;
            std::cout << "Enter T1: ";
            std::cin >> T1;
            std::cout << "Enter T2: ";
            std::cin >> T2;
            Q = solveQ(M, C, T1, T2);
            std::cout << Q << " is your answer";
            return 0;
        }

    if (choice == 2)
        {
            std::cout << "Enter Q: ";
            std::cin >> Q;
            std::cout << "Enter C: ";
            std::cin >> C;
            std::cout << "Enter T1: ";
            std::cin >> T1;
            std::cout << "Enter T2: ";
            std::cin >> T2;
            Q = solveM(Q, C, T1, T2, T);
            std::cout << M << " is your answer";
            return 0;
        }
}

int solveQ(int M, int C, int T1, int T2)
    {
        int Q;
        Q = (M * C * (T1 - T2));
        return Q;
    }

int solveM(int Q, int C , int T1, int T2, int T)
    {
        int M;
        T = (T1 - T2);
        M = (Q / C / T);
        return M;
    }


For example when I run it I use 10 as Q, 1 as C, 5 as T1, and 4 as T2. I would expect this to come out as 10 but instead it comes out as 4201376.
1
2
           Q = solveM(Q, C, T1, T2, T);
            std::cout << M << " is your answer";


Yello. Q != M.

[edit: There is no reason for T to be a parameter to solveM.]
Last edited on
Thank you cire, even after looking over it one hundred times I completely missed that one.
Topic archived. No new replies allowed.