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

1. Write a C++ program that prompts the user for a double that should be between

ID: 3552602 • Letter: 1

Question

1. Write a C++ program that prompts the user for a double that should be between 0 and 100. If the value entered is outside of the interval the program will print an error message. The program should continue to repeat until the user enters an appropriate value.


2. Write a C++ program that prompts the user for a double that is either positive or negative. If positive it prints the square root in a statement for example The sqrt(49) = 7. If the number is negative it will take the absolute value of the number and then print

the imaginary value. For example, The sqrt(-49) = 7i.

Explanation / Answer

1. working code


#include<iostream.h>
main()
{
    double num;
    cin >> num;
    while (1)
    {
    if (num <0 || num >100)
    {
        cout<<"enter again wrong value ";
        cin>>num;
        if (num < 0 || num >100)
        {
            continue;
        }
    }
    else
    {
        break;
    }
}
}


2. working c code


#include<iostream.h>
#include<math.h>
main()
{
    double num;
    cin >> num;
    if (num>0)
    num=sqrt(num);
    else
    num=abs(num);
    cout <<num;
}



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote