-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (36 loc) · 836 Bytes
/
main.cpp
File metadata and controls
46 lines (36 loc) · 836 Bytes
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
#include <iostream>
#include <limits>
#include "function.h"
using namespace std;
int main(){
cout << "Enter your first number: ";
bool valid_a = false;
bool valid_b = false;
int a{};
int b{};
while(!valid_a){
if(cin >> a){
cout << "Enter your second number: ";
valid_a = true;
}
else {
cout << "Invalid input. Try again: ";
cin.clear(); //clear error state
cin.ignore(numeric_limits<streamsize>::max(), '\n'); //ignore invalid input
}
}
while(!valid_b){
if(cin >> b){
valid_b = true;
}
else {
cout << "Invalid input. Try again: ";
cin.clear(); //clear error state
cin.ignore(numeric_limits<streamsize>::max(), '\n'); //ignore invalid input
}
}
cout << "Your numbers are " << a << " and " << b << "." << endl;
for(int i = a; i <= b; i++){
factors(i);
}
}