In: Computer Science
Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in Assignment 04.1 to C++ code inside the main() function. Your program should prompt for a single 9-digit routing number without spaces between digits as follows: Enter a 9-digit routing number without any spaces: The program should output one of: Routing number is valid Routing number is invalid A C++ loop and integer array could be used to extract the routing number's 9 digits. However since we have not yet covered C++ loops and arrays in class, you can instead assign the digits to integer variables d0,d1,d2,d3,d4,d5,d6,d7,d8 without any point deduction. Doing the latter should help you to understand looping over an array since you have essentially unrolled the loop. This illustrates two conventions: C++ arrays start with index 0, and the 0thdigit is the rightmost digit. Try your program on the following routing numbers: 111000025 and 789456123 One of them is a valid routing number and one of them isn't. Copy and paste the console output for these two routing numbers to a text editor and save the result in a single file named console.txt. Upload the assignment042.cpp and console.txt files to Canvas.
assignment042.cpp
#include <iostream>
using namespace std;
int main(){
// integer variables to store all digits of routing number
int d0, d1, d2, d3, d4, d5, d6, d7, d8;
// taking input from console by one digit using %1d
// this makes input of 9 digit routing number with no spaces
cout << "Enter a 9-digit routing number without any spaces: ";
scanf_s("%1d%1d%1d%1d%1d%1d%1d%1d%1d", &d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, sizeof(d0)*9 );
// Below is code to check if a number is valid routing number
// Number is divided into three parts
// Those digits will be multiplied by 3, 7, 1 respectively
// Then all the products will be added
// If the result is a multiple of 10 then Routing number is valid
// Else not a valid routing number
int value;
// storing the reult in value variable
value = (d0 * 3) + (d1 * 7) + (d2 * 1) +
(d3 * 3) + (d4 * 7) + (d5 * 1) +
(d6 * 3) + (d7 * 7) + (d8 * 1);
// 10 multiple check to verify a valid routing number
// Divisible by 10 if reminder is zero
if (value % 10 == 0){
cout << "Routing number is valid";
}
else {
cout << "Routing number is invalid";
}
}
console.txt
Enter a 9-digit routing number without any spaces: 111000025
Routing number is valid
Enter a 9-digit routing number without any spaces: 789456123
Routing number is invalid
Have a nice day!