This is the program I got so far and it compiles and everything, it\'s just Idk
ID: 3535547 • Letter: T
Question
This is the program I got so far and it compiles and everything,
it's just Idk how to add a function to get a positive integer as a
string. It's basically like error checking. I the user doesn't
enter a positive integer, they get another prompt and chance. and
it should keep asking until a positive integer is inputed. It has
to be a strin but I have no idea how to. Another one is Now, write
a function, is_positive_int(), responsible for checking that the
string entered by the user is a positive integer. It will return a
1, if the string is a positive  number, and the
function will return 0 otherwise.
1 #include
2 #include
3 #include
4
5 using namespace std;
6 int num, num2;
7
8 void countUp (int num)
9 {
10 for (int i=0; i<= p="">num; i++)
11 std::cout << i << ' ';
12 }
13
14 void countDown (int num)
15 {
16 for (int i = num;i>= 0; i--)
17 std::cout << i << ' ';
18 }
19
20 void countBoth (int num, int num2)
21 {
22 if (num >= num2)
23 for (int x= num; x>= num2; x--)
24 std::cout << x << ' ';
25 if (num <= num2="" p="">
26 for (int x= num; x
27 std::cout << x << ' ';
28
29 }
30
31
32 int main()
33 {
34
35 int num, num2;
36
37 cout << "Please enter a positive integer. ";
38 cin >> num;
39 cout << "Enter another positive integer. ";
40 cin >>num2;
41
42 int x = num;
43 countUp(x);
44
45 cout <<" "; p="">
46
47 countDown(x);
48
cout <<" "; div="">
Explanation / Answer
You need to use this:
You basically need to convert from string to integer for comparison.
std::string myString = "45"; int value = atoi(myString.c_str()); //value = 45 Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.