Answer to Question #139586 in C++ for sanya

Question #139586
Write a C++program that reads the number of water bottles you want to buy and prints the total price you must pay. For example, if you buy five water bottles then the total price printed must be 1.50 + 1.45 + 1.40 + 1.35 + 1.30 which is 7 d
1
Expert's answer
2020-10-22T11:11:00-0400
#include <iostream>
using namespace std;
int main() {
    int number;
    double price = 1.5;
    double total = 0;
    cout << "Enter number of water bottles: ";
    cin >> number;
    for (int i = 0; i < number; ++i) {
        total += price;
        price -= 0.05;
    }
    cout << "Total price is: " << total << "$";
    return 0;
}


Outputs:









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
APPROVED BY CLIENTS