Question

What is wrong, if anything, with the following code? ​ double price = 0; cout <<...

What is wrong, if anything, with the following code?

double price = 0;

cout << "Item price: ";

cin >> price;

do

{

cout << "Total cost: $" << price + price * .05 << endl;

cout << "Item price: ";

} while (price > 0);

​​

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

here in this code, when you run this code you will get an infinite iteration of while loop. this happens because there is no decrement or increment of the price to check the condition in while loop.

if you put number is positive and decrement that loop by some value then it will give a valid output.

Add a comment
Know the answer?
Add Answer to:
What is wrong, if anything, with the following code? ​ double price = 0; cout <<...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What did I do wrong with this C++ code? Assume that we don't need to ask...

    What did I do wrong with this C++ code? Assume that we don't need to ask users for the number of students. #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size; int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total; // average grade and total grades //**************start your code here************************ cout<<"How many student grades...

  • 1. Briefly explain what is wrong (exactly 1 error) with the following code. auto input =...

    1. Briefly explain what is wrong (exactly 1 error) with the following code. auto input = 0.0; cout << "Enter input: "; cin >> input; cout << "Result 1 = " << 1.0 / input << endl; cout << "Result 2 = << input * input 2 * input << endl; cout << "Result 3 = << input + (9- input) << endl; 11

  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • //What's wrong with my code? int run() {    // Don't change anything inside this function...

    //What's wrong with my code? int run() {    // Don't change anything inside this function    printTitle();    string letterGrade = getInput();    double points = letterToPoints(letterGrade);    printReport(points); return 0; } // Implement your functions here void printTitle() {     cout << STUDENT << "-H02-Grade Calculator" << endl;    cout << "-----------------------------------------" << endl; } string getInput() {    cout << "Enter your letter grade: ";    string gradeIn;    getline(cin, gradeIn);    cin >> gradeIn;    return...

  • Find and fix the errors in this C++ code: * This program illustrates a variety of...

    Find and fix the errors in this C++ code: * This program illustrates a variety of common loop errors. * Fix the errors in each section. */ #include <iostream> using namespace std; int main() { cout << "Welcome to Loop World" << endl; // SECTION I: update comment below on how you fixed this section's code, and tests run // FIX = // TESTS: cout << endl; cout << "******************" << endl; cout << "Section I" << endl; cout <<...

  • Can sombody tell me what wrong for this code to work?? It is c++ btw. thanks!...

    Can sombody tell me what wrong for this code to work?? It is c++ btw. thanks! #include <iostream> #include <string> using namespace std; double op1; double op2; string ADD; string SUBTRACT; string MULTIPLY; string DIVIDE; string selection; string multiply; string divide; string add; string subtract; string "*"; string "+"; string "-"; string "/"; int main() { do { cout << "--------WELCOME TO THE CALCULATOR----------" << endl; cout << "Enter your first operand: "; cin >> op1; cout << "Enter your...

  • How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0,...

    How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return n; } return fibonacciRecursive(n-1) + fibonacciRecursive(n-2); } int main() { int n;...

  • im writing a c++ code and getting stuck on two parts. The first part, when I...

    im writing a c++ code and getting stuck on two parts. The first part, when I go to write the customer order out to the file, it writes everything but the price out right. I'll get a weird number like 5.95828e-039 or nan. When I printout to the console it works fine so not sure what's wrong. Second After I write the order out to the file, I then have to go in and read the file and calculate the...

  • PLEASE, CLEARLY EXPLAIN THE ANSWER OF THE FOLLOWING QUESTION: - What is wrong with the following...

    PLEASE, CLEARLY EXPLAIN THE ANSWER OF THE FOLLOWING QUESTION: - What is wrong with the following code snippet? cout << "Please enter a number: "; cin >> b; if (b > 100)    cout << "Your number " << b << endl;    cout << " was greater than 100" << endl; It has a syntax error. Nothing is wrong. Braces should have been included after the if() statement to clarify which statements are conditional. The comparison should be (b <...

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT