i am a University student pursuing a degree in computer science, it seems as though i really suck at validating things... well I just don't really get the concept i know its conditions but i when i try one it always seems to crash my program I've been trying to validate this program for some time can someone please help asap or and i need to make sure the input are integers only and character/letters
thanks in advance..:)
#include<iostream>
using namespace std;
int main()
{
//Declear variables
int num_people= 0;
int total_num_people= 0.0;
double total_charge= 0.0;
double avg_charge=0.0;
double total_cost=0.0;
//prompt
cout<<"Enter amount of persons attending from Campany:"<<endl;
cout<<"Enter -1 to see your total charge otherwise continue entering number of persons:"<<endl;
cin>>num_people;
while(num_people!=-1){
//calculate total charge and average per registrant
total_num_people= total_num_people + num_people;
//display total amount people
cout<<"Total amount of people are:"<<total_num_people<<endl;
//prompt
cout<<"Enter amount of persons attending from Campany:"<<endl;
cin>>num_people;
}//end while
//conditons
if(total_num_people>= 1 && total_num_people<= 3)
{
//calculate total charge and avg charge
total_charge= total_num_people * 150;
avg_charge= total_charge/total_num_people;
total_cost=total_charge+avg_charge;
//display total charge
cout<<"Your total charge is:"<<total_charge<<endl;
cout<<"your Average charg per person is:"<<avg_charge<<endl;
cout<<"Your total cost is:"<<total_cost<<endl;
}//end if
else
if(total_num_people>=4 && total_num_people<=9)
{
//calculate total charge and average per registrant
total_charge=total_num_people*100;
avg_charge= total_charge/total_num_people;
total_cost=total_charge+avg_charge;
//Display total charge
cout<<"Your total charge is:"<<total_charge<<endl;
cout<<"Your Average charg per person is:"<<avg_charge<<endl;
cout<<"Your total cost is:"<<total_cost<<endl;
}//end else if
else{
//calculate total charge, avg charge and total cost
total_charge= total_num_people*90;
avg_charge= total_charge/total_num_people;
total_cost=total_charge+avg_charge;
//display total charge
cout<<"Your total charge is:"<<total_charge<<endl;
cout<<"Your Average charg per person is:"<<avg_charge<<endl;
cout<<"Your total cost is:"<<total_cost<<endl;
}//end if
return 0;
}