Question

Using C++, change the formatting in this code by using set precision and set width. The...

Using C++, change the formatting in this code by using set precision and set width. The decimals should line up.

#include

using namespace std;

int main()
{
int start, end;
int ch=1;

do{
cout<<"Enter starting and ending range";
cin>>start;
cin>>end;
if(end36)
{
cout<<"Invalid range\n";
continue;
}
cout<<"Inches\tCentimeters\n";
cout<<"******\t***********\n";

for(int i=start;i<=end;i=i+6){
cout< }
cout<<"Do you want to continue -1 to quit";
cin>>ch;
}while(ch!=-1);

return 0;
}

Homework Answers

Answer #1
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int start, end;
    int ch = 1;

    do {
        cout << "Enter starting and ending range";
        cin >> start;
        cin >> end;
        if (end < start) {
            cout << "Invalid range\n";
            continue;
        }
        cout << "Inches\tCentimeters\n";
        cout << "******\t***********\n";

        for (int i = start; i <= end; i = i + 6) {
            cout << setw(10) << setprecision(2) << fixed << left << i << setprecision(2) << fixed << 2.54*i << endl;
        }
        cout << "Do you want to continue -1 to quit";
        cin >> ch;
    } while (ch != -1);

    return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial...
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial of a number Compute the alternating factorial of a number Quit #include <iostream> using namespace std; void getValidUserInputPosNumGT0 (int *a) { int num; cout << "Enter in a positive number greater than 0... "; cin >> *a; } long double factorial (int num) { int fact = 1; while (num > 1) { fact *= num; num--; } return fact; } long double AlternatingFactorial...
I'm writing a fairly simple program in C++ and i keep getting an error message when...
I'm writing a fairly simple program in C++ and i keep getting an error message when i try to compile it I don't see what I'm doing wrong if someone could look at this and point me in the right direction? #inlcude <iostream> using namespace std; int main() {    int length, width, area;       cout<<"This program calculates the area of a ";    cout<<"rectangle.\n";    cout<<"What is the length and width of the rectangle ";    cout<<"separated by...
How do I make this code not include negative numbers in the total or average if...
How do I make this code not include negative numbers in the total or average if they are entered? (C++) For example, if you enter 4, 2, and -2, the average should not factor in the -2 and would be equal to 3. I want the code to factor in positive numbers only. ----- #include using namespace std; int main() {    int x, total = 0, count = 0;       cout << "Type in first value ";   ...
C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether...
C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether a college class room is in violation of fire law regulations regarding the maximum room capacity and add more logic to that program. We will need to make the following enhancements… The program should now determine the number of classes, and should do so by generating a unique, random number. Replace taking user input for the number of rooms with a computer generated number...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment 2 (karatsuba.cpp) in Canvas (please do not rename file or use cout/cin statements in your solution). As a reminder, the algorithm uses recursion to produce the results, so make sure you implement it as a recursive function. Please develop your code in small The test program (karatsuba_test.cpp) is also given. PLEASE DO NOT MODIFY THE TEST FILE. KARATSUBA.CPP /* Karatsuba multiplication */ #include <iostream>...
c++ Language Fix this code to have it concatenate two strings st1 and st2 and put...
c++ Language Fix this code to have it concatenate two strings st1 and st2 and put the result in st3 with a space separator. it has to be done using array representation of strings #include <iostream> using namespace std; #include <string> int main() { string st1,st2, st3; int c = 0, i =0;    cout << "Enter a string: "; cin >> st1; cout << "Enter another string: "; cin >> st2;    while (st1[c] != '\0'){ st3[c] = st1[c];...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You must...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT