Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When the user inputs DONE The total invoice cost is 0 when I want it to be 0.0 but I cant figure out whats wrong.

When the user inputs "DONE" The total invoice cost is 0 when I want it to be 0.0 but I cant figure out whats wrong.

Input: DONE

My output:

Item:

Item Quantity Price Total Cost

Total invoice cost: $0

Output I want:

Item:

Item Quantity Price Total Cost

Total Invoice Cost: $0.00

by second problem is when the user put in DONE at the end, "Item:" shows up at the top when I dont want it to show up. I need help to try and fix the loop.

input:

Tennis Shoes, 4 45.88 Brand name Ankle Socks, 7 1.99 Knock-offs Sweat band, 3 2.50 Insulated water bottle, 2 4.20 Keep hydrated!! DONE

My output:

Item:

Item Quantity Price Total Cost Tennis Shoes 4 $45.88 $183.52 Ankle Socks 7 $1.99 $13.93 Sweat band 3 $2.5 $7.5 Insulated water bottle 2 $4.2 $8.4

Total invoice cost: $213.35

output I want:

Item Quantity Price Total Cost Tennis Shoes 4 $45.88 $183.52 Ankle Socks 7 $1.99 $13.93 Sweat band 3 $2.50 $7.50 Insulated water bottle 2 $4.20 $8.40

Total Invoice Cost: $213.35

My code:

#include #include #include

using namespace std;

int main() { string line, name; int index, q; float price, total = 0; ostringstream oss; oss << "Item Quantity Price Total Cost" << endl; while (true) { getline(cin, line); if (line == "DONE"){ cout << "Item: " << endl; break; }

index = line.find(','); name = line.substr(0, index); istringstream iss(line.substr(index + 1)); iss >> q >> price; oss << left << setw(30) << name << left << setw(10) << q << "$" << left << setw(10) << price << "$" << left << setw(12) << price * q << endl; total += (price * q); }

cout << endl << oss.str() << endl << endl; cout << "Total invoice cost: $" << total << endl; return 0; }

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

Recommended Textbook for

More Books

Students also viewed these Databases questions