I was assigned to write this code and it seemed pretty simple at first. I wrote it out and tried to understand it as best as I could and really thought I got it down. But when I tried to check the code using VisualStudio, errors with the code popped up and the code would not finishing processing.
Here's the assignment:
Write a function named specialNumbers that computes and returns the total number of integers between two target numbers that are divisible by 3. The function takes two parameters: 1. start, an integer 2. end, an integer bigger than start The function returns the total number of multiples of 3, between start and end, inclusive. For example, if start=3, end=10, the function would return 3.
Here is the code I have so far:
#include <iostream>
using namespace std;
int specialNumbers(int start, int end) {
int count = 0;
for (int i = start; i < end; i++) {
if (i % 3 == 0)
count++;
}
return count;
}
int main() {
int a, b;
cout << "Enter two numbers to find total number of integars divisble by 3 between them" << endl;
cin >> a, b;
int n = specialNumbers(a, b);
cout << "Number of integars divisible by 3 between" << a << "and" << b << "are" << n << endl;
return 0;
}
The error is displays is
Debug Error! The variable b is used and not initialized