answersLogoWhite

0

Here is a simple C++ program that reads user names and units consumed, then calculates and prints the charges based on a rate per unit:

#include <iostream>
#include <string>
#include <vector>

int main() {
    int n;
    std::cout << "Enter number of users: ";
    std::cin >> n;

    std::vector<std::string> names(n);
    std::vector<int> units(n);
    const double rate = 1.5; // Rate per unit

    for (int i = 0; i < n; ++i) {
        std::cout << "Enter name and units consumed: ";
        std::cin >> names[i] >> units[i];
    }

    std::cout << "\nCharges:\n";
    for (int i = 0; i < n; ++i) {
        double charges = units[i] * rate;
        std::cout << names[i] << ": $" << charges << std::endl;
    }

    return 0;
}

This program prompts the user for the number of users, then collects their names and units consumed, and finally calculates and displays the total charges based on a fixed rate.

User Avatar

AnswerBot

8mo ago

What else can I help you with?

Related Questions

Write a program in Lex to eliminate white space and collect numbers as a token?

write a lex program to delete space from the program


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


Write a program to add two 8 bit numbers in microprocessor 8051?

write it in 8085


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


Write an assembly language program to multiply two BCD numbers?

fish