forked from berea-college-csc236/T03-Debug-Me-MASTER
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-main.cpp
More file actions
37 lines (30 loc) · 1.19 KB
/
debug-main.cpp
File metadata and controls
37 lines (30 loc) · 1.19 KB
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
/* T03: Debug-Me!
This program is designed to learn more about data types and
facilitate the use of the IDE's debugging tools.
Original code by Dr. Jan Pearce, Berea College */
#include <iostream>
using namespace std;
int main() {
int userval = 500, noextra;
double finddigit, asciival;
char digit, stopme;
cout << "WELCOME TO DEBUGME! Your debugging help is needed to make this program work correctly!\n" << endl;
cout << "This program is designed to print the digits of a positive integer in reverse order." << endl;
cout << "But, it sometimes fails and needs your help debugging!" << endl;
cout << "\nEnter a negative number to end. " << endl;
while (userval > 0) {
cout << "To continue, please enter a positive number: ";
cin >> userval;
noextra = userval; //Implict "cast" from double that truncates userval if entered as double
while (noextra > 0) {
finddigit = noextra / 10.0; //double
noextra = noextra / 10; //int
asciival = (finddigit - noextra) * 10 + 48; //converts digit to ascii
digit = asciival; //converts to an integer
cout << "digit: " << digit << endl;
}
}
cout << "\nProgram complete. Close console.";
cin >> stopme;
return 0;
}