76 283
Assignments Done
98,4%
Successfully Done
In May 2019

Answer to Question #41683 in C++ for Tina

Question #41683
Write a program that prompts the user to enter a 3-digit integer. Then, if the integer is not an integer containing exactly 3 digits or is a 3-digit number begining with a 0, prompt the user again. Repeat this until the user correctly enters a 3-digit integer. Once the user has successfully entered the three digit integer, display the three digits on three separate lines.
Expert's answer
#include <iostream>
using namespace std;
int main() {
int workingNumber, disas[3];
cout << "Please input 3 digit integer which does not begin with zero" << endl;
cin >> workingNumber;
while ( workingNumber < 100 || workingNumber > 999 ) {
cout << "You were suposed to input 3 digit integer which does not begin with zero" << endl;
cin >> workingNumber;
}
for ( int i = 2; i >=0; i-- ) {
disas[i] = workingNumber % 10;
workingNumber /= 10;
if ( disas[0] == 0 ) {
cout << "You were suposed to input 3 digit integer which does not begin with zero" << endl;
cin >> workingNumber;
}
}
for (int i = 0; i < 3; i++ ) {
cout << disas[i] << endl;
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions