Answer to Question #146574 in C++ for dina

Question #146574
Initialize total to 0
Initialize customer to ‘Y’
While
there is still a customer
Input quantity
Input price
Accumulate total
Continue for another customer?
Input customer
Display total paid by all customers
1
Expert's answer
2020-11-24T10:13:03-0500
#include<iostream>


int main(){


    int total, quantity, price;
    char customer = 'Y';


    total = 0;


    do{
        std::cout << "Customer: " << customer << std::endl;
    	std::cout << "Input a quantity: " << std::endl;
    	std::cin >> quantity;


    	if(std::cin.fail()){
    		std::cin.clear();
    		std::cin.ignore(255, '\n');    		
    		continue;
    	}


    	std::cout << "Input a price: " << std::endl;
    	std::cin >> price;


    	if(std::cin.fail()){
             std::cin.clear();
             std::cin.ignore(255, '\n');
             continue;
    	}


    	total += price * quantity;


    	std::cout << "Continue for another customer? ('n' or 'N' to exit)" << std::endl;


    	std::cin >> customer;


    	if(customer == 'N' || customer == 'n')break;


    }while(customer != 'n' || customer != 'N');


    std::cout << std::endl;
    std::cout << std::endl;


    std::cout << "Total paid for all customers: " << total << std::endl;


	return EXIT_SUCCESS;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog