Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Procedure, with Mixed (Value and Reference) Parameters (please use C++ format) W

ID: 3626112 • Letter: P

Question

Procedure, with Mixed (Value and Reference) Parameters (please use C++ format)
Write a program that prompts the user to enter an integer (0-999), and then outputs each digit separately.

The user should be able to enter integers and see the digits as often as they want - a negative integer will signal the program to quit.
An input value greater than 999 should trigger the response "Invalid input: try again".

For this program, you should have at least one procedure, called find_digits: Since up to three separate items need to be extracted from the input, and since a function can only return a single value through a return statement, you will instead have to use pass-by-reference parameters to "pass back" the digits.

So your procedure should have a return type of void and take 4 parameters: the number itself (should be a value parameter), and a reference parameter for each digit of the number.

Explanation / Answer

#include<iostream>
using namespace std;
void find_digits(int &z,int &a,int &b,int &c)
{
a = z%10;
int p = z/10;
b = p%10;
int q = p/10;
c = q%10;
}
int main()
{
int a=0,b=0,c=0,n;
cout << "Enter A number :";
cin >> n;
find_digits(n,c,b,a);
cout << "Your Digits are :"<<endl;;
cout << "First Digit is " << a << endl;
cout << "Second Digit is " << b << endl;
cout << "Third Digit is " << c << endl;
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote