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;


}

One approach is to treat all of your input as chars say using std::srting

#include <string>
#include <iostream>

int main()
[
 std::string input;
 std::cout << "please enter data" << std::endl;
 std::cin >> input;

//using an int instead of sizetype f
//step over each char of input
int sz = (int) input.size();
for(int i(0); i < sz; ++i)
{
//current letter
  char c = input[i];
  if(c >= 'a' && c <= 'z')
  {
    //lower case
  }
  else if(c >= 'A' && c <= 'Z')
  {
     //upper case
  }
  else if(c >= '0' && c <= '9')
  {
    //digit
  }
  else
  {
     //? unexppected char 
   }
}
 return 0;
}

The idea is that you use the ascii charcater codes to decide
what each char is. Now you can convert the string of digits to a number if it is only digits will also
have to consider: decimal point (full stop) and minus

now there are other ways of handling the input and functions that will convert strings to numbers.

please help asap or and i need to make sure the input are integers only and character/letters

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.