Write a program to calculate the total cost from shopping for n commodities. The input consists of an integer n, followed by n pairs or doubles. In each pair, the first number is the quantity bought of the commodity, and the second the rate per unit for the commodity. The amount to be paid for each commodity is the product of the quantity and the rate; the program must print the total over all commodities. For example if the input is 3 2 30 3 10 5 60, the expected answer is 2*30 + 3*10 + 5*60 = 390.using c++
Answers
Answered by
4
Answer:
#include<iostream >
using namespace std;
int main()
{
int n, x, y, s=0;
cin>>n;
for(int i=0;i<n;++i)
{
cin>>x>>y;
s=s+(x*y);
}
cout<<s;
}
Answered by
0
A program to calculate the total cost from shopping for n commodities is as follows:
#include<iostream.h>
int main ( )
{
int n, total = 0, a[30], p, q=0;
cin>>n;
n=2*n;
for (p=0; p<n; p++)
{
cin>>a[p];
}
for (p=0; a[p] ! ='\0' ; p++)
{
q=p+1;
total = total +a[p] * a[q];
p=q;
}
cout<<total<<"\n";
return 0;
}
Similar questions