Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help improving my C++ code by replacing the if statements with a while loop because I have an error when trying to

Hello, I need help improving my C++ code by replacing the if statements with a while loop because I have an error when trying to enter a value above the range and the program needs to be tested for at least seven integer values between 2,000,000,000 and a number outside the long int data range as stated in the requirements circled in red. Thanks.

Code:

#include #include #include

using namespace std;

int main() {

fstream output; long int num; // you cant use small c, as cout is a keyword in c++. char exit = NULL;

output.open("output.txt", fstream::out);

output

if (output.is_open()) {

while (exit != 'n' && exit != 'N') {

cout > num;

if (num > -10 && num -100 && num = 10 && num -1000 && num = 100 && num -10000 && num = 1000 && num -100000 && num = 10000 && num -1000000 && num = 100000 && num -10000000 && num = 1000000 && num -100000000 && num = 10000000 && num -1000000000 && num = 100000000 && num 2000000000 || num -10000000000 && num = 1000000000 && num

cout > exit; } output.close(); } else cout

return 0;

}

Requirements:

image text in transcribed

Output with error:

image text in transcribed

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 rejects any input outside the long integer data range. following table. VALUE ENTERED NUMBER OF DIGITS 1241 19 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 do you want to continue? (y) Input number: The number is too large do you want to continue? (y) Input number: The number is too large do you want to continue? (y) Input number: The number is too large do you want to continue? (y) Input number: The number is too large do you want to continue? (y) Input number: do you want to continue? (y) Input number: The number is too large do you want to continue? (y) Input number: The number is too large do you want to continue? (y) Input number: The number is too large do you want to continue? (y) Input number: The number is too large Input number

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions