Wednesday, 19 June 2013

source code: Boolean Flag using C++ (total / average price) [easy and user friendly]


#include <iostream>
using namespace std;

int main (){

bool proceed= true;
    int items= 0,p;
    double price, totalPrice=0;
    cout<<"Program To Calculate and show the Average and Total Price Of Items \n\n";

    while(proceed)

    {
        cout<<"Enter price of item: "; cin>>price;
        totalPrice += price;
        items++;


        cout<<"Anymore item? Enter 1 for yes OR 0 for no: "; cin>>p;


try

{
if(p>1)
{
throw 1;
}else{proceed=p;}
}
catch(...)
{
cout<<"aA ah, i said 1 for YES and 0 for NO, OONNLLYY !!\n\nAnymore item? Enter 1 for yes OR 0 for no: "; cin>>p;
}

    }

    cout<<"\n\nNumber of items: "<<items <<"\nThe Average Price Of The Items Is "<<totalPrice/items;

    cout<<"\nThe Total Price of the Items Is "<<totalPrice <<"\n\nthank you for using this software :)\n\n";

}


No comments:

Post a Comment