...
/Solution Review: Convert Digits from 0 to 5 into Text
Solution Review: Convert Digits from 0 to 5 into Text
Let's go over the solution review of the challenge given in the previous lesson.
We'll cover the following...
Solution #
Press the RUN button and see the output!
Press + to interact
#include <iostream>using namespace std;string digit_text (int number){// Declares a variable of type stringstring result ;switch (number){case 0:result = "zero";break;case 1:result = "one";break;case 2:result = "two";break;case 3:result = "three";break;case 4:result = "four";break;case 5:result = "five";break;default:result = "invalid number";}return result;}int main() {int number = 3;cout << "number = " << number << endl;string text;text = digit_text(number);cout << "text = " << text << endl;return 0;}
Explanation
On Line No. 4, we define our function digit_text
that takes an ...