Code in Visual Studio C++ beginner/intermediate code Write a program to read an
ID: 3888381 • Letter: C
Question
Code in Visual Studio C++ beginner/intermediate code
Write a program to read an integer number and find its number of digits (for example, 3459 has 4 digits and 125860 has 6 digits) The program should be designed in a way that the user could test as many numbers as desired without leaving the program. Use only long integer (int or long int) data type in this problem: however make sure that the program The outputs of the program should be written to an output file having a format similar to the following table. NUMBER OF DIGITS 1241 19 5684900 Al 1267678901 -153 62000 Test the program for at least seven integer values between ± 2.000.000.000 and a number outside the long int data range. Remember to submit a copy of the program file and a copy of the output file. Note: You should use while or do-while loop in this assignment.Explanation / Answer
Ans : When you excecute this program a OutputTxt.txt file will be created in the folder where your ide resides.
program.cpp :
#include <iostream>
#include<fstream>
using namespace std;
int main()
{
long int number,digit;
char ch;
fstream file;
file.open("OutputTxt.txt",ios::out);
file <<"VALUE ENTERED NUMBER OF DIGITS"<<endl;
do
{
try{
cout<<"Enter a number : ";
cin>>number;
digit=0;
while(number>0)
{
number = number/10;
digit++;
}
cout<<"Number of digits : "<<digit<<endl;
file <<number<<" "<<digit<<endl;
cout<<" Do you wish to continue(Y/N) : ";
cin>>ch;
}
catch(...)
{
}
}
while(ch =='y' || ch=='Y');
file.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.