#include <iostream>
#include <conio>
int main()
{
int N, itemCnt=0;
double price, totalPrice=0;
cout<<"Program To Calculate The Average and Total Price Of N Items \n\n";
cout<<"How many items? ";
cin>>N;
do
{
cout<<"Enter price of item: ";
cin>>price;
totalPrice+=price;
itemCnt++;
} while (itemCnt<N);
cout<<"\n\nYou have "<< itemCnt <<" Items";
cout<<"\nThe Average Price Of The Item Is "<<totalPrice/itemCnt;
cout<<"\nThe Total Price Of The Item Is "<<totalPrice;
cout<<"\n\nEnd Of Program";
getch();
return 0;
}
#include <iostream>
#include <conio>
int main()
{
int N=0, P;
double price, totalPrice=0;
cout<<"Program To Calculate The Average and Total Price Of N Items \n\n";
cout<<"How many items? ";
cin>>N=P;
do
{
cout<<"Enter price of item: ";
cin>>price;
totalPrice+=price;
N--;
} while (N/=0);
cout<<"\n\nYou have "<< N <<" Items";
cout<<"\nThe Average Price Of The Item Is "<<totalPrice/P;
cout<<"\nThe Total Price Of The Item Is "<<totalPrice;
cout<<"\n\nEnd Of Program";
getch();
return 0;
}
I tried to eliminated itemCnt from the original program, but then replace the cin>>N; to cin>>N=P; because don't want my N=0 at this line cout<<"\nThe Average Price Of The Item Is "<<totalPrice/itemCnt; after change become cout<<"\nThe Average Price Of The Item Is "<<totalPrice/N; where any number cannot be divided with 0, that why I change my code to this cout<<"\nThe Average Price Of The Item Is "<<totalPrice/P;
I think cin>>N=P; is wrong, is that possible to have something like N=P; to solve the problem above?
Somemore, is that correct to write not-equal in this way (N/=0)? Thanks...
#include <iostream>
#include <conio>
int main()
{
int N=0, P;
double price, totalPrice=0;
cout<<"Program To Calculate The Average and Total Price Of N Items \n\n";
cout<<"How many items? ";
cin>>N;
P=N;
do
{
cout<<"Enter price of item: ";
cin>>price;
totalPrice+=price;
N--;
} while (N not_eq 0);
cout<<"\n\nYou have "<< P <<" Items";
cout<<"\nThe Average Price Of The Item Is "<<totalPrice/P;
cout<<"\nThe Total Price Of The Item Is "<<totalPrice;
cout<<"\n\nEnd Of Program";
getch();
return 0;
}
Thanks chipp for the library, it do help in Ms Visual Studio C++ but not Borland C++, I think Borland C++ is really out of date...lolx...
Moschops, is that Ms Visual Studio 2010 C++ consider out of date? Coz if I don't put this library #include <iso646.h> , it won't work as well...I don't know about that, pls guide, thanks...
Thanks chipp for the library provided...it do help in Visual Studio 2010 C++ but not in Borland C++, I think Borland C++ is really out of date...
Moschops, is that Ms Visual Studio 2010 C++ consider out of date? Coz I only can use it without any error if have #include <iso646.h> inside...I not really know about this, pls guide, thanks~~