Return always 0?

Can any one help find why my return value is always 0?

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

double getGrade(int, int);

int main()
{
    int ammount, correct;
    double grade;
    
    std::cout << "How many questions?\t";
    std::cin  >> ammount;
    std::cout << "How many correct?\t";
    std::cin  >> correct;
    
    grade = getGrade(ammount, correct);
    
    std::cout << grade<< "%\n";
}

double getGrade(int a, int b)
{
    double temp_grade;
    
    temp_grade = (b/a)*100;
    
    return temp_grade;
}


I feel like I suck having to ask this with 3 months of coding with c++.
You are doing integer division on line 24. Cast one of a or b to double before dividing.
you should also prevent that a is equal to zero .
closed account (48T7M4Gy)
temp_grade = (b*100/a);
Topic archived. No new replies allowed.