Function and loop addition program

I'm at a lost for how to fix this. It compiles perfect but doesnt do what I want it to. What I'm trying to do is run a program that generates 2 random numbers(up to 10) for an addition problem while running a function/subprogram in a 5 count controlled loop. What am I doing wrong here? Can someone please help?

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
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

void additionProblem(int topNumber = rand() % 10, int bottomNumber = rand() % 10)
{
    
    int userAnswer;
    cout << "\n\n\n       " << topNumber << " + " << bottomNumber << " = ";
    cin >> userAnswer;
    cin.ignore(1000, 10);
    
    int theAnswer = topNumber + bottomNumber;
    
    if (theAnswer == userAnswer)
        cout << "     Correct!" << endl;
    else
        cout << "     Very good, but a better answer is " << theAnswer << endl;
}

int main()
{
    
    int i;
    i = 0;
    while(i < 5);
    
    {
    srand(time(0));
        
    additionProblem();
        
    i = i + 1;
    }
    
}
I guess you are stuck in an infinite loop. Remove the semicolon at the end of line 27. Also, if you want to generate different sets of random numbers, you need to move line 30 before your while loop
Topic archived. No new replies allowed.