I HAVE THIS CODE....but unfortunately when entering values, the 'Destination' string gets bypassed and jumps over to distance. PLEASE HELPPP !!!
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <windows.h>
using namespace std;
class flight
{
private:
int fno; //flight no
char dest[20]; //destination
float dist; //distance
float fuel; //fuel required
void calfuel(); //calculating fuel - function
public:
void getdata();
void outdata();
};
void flight::outdata()
{
calfuel();
cout<<"Flight No. : "<<fno;
cout<<"\nDestination : "<<dest;
cout<<"\nDistance : "<<dist<<" kms";
cout<<"\nFuel required : "<<fuel<<" kgs";
}
void flight::getdata()
{
cout<<"Enter Flight No. : ";
cin>>fno;
cout<<"Enter Destination : ";
gets(dest);
cout<<"Enter Distance : ";
cin>>dist;
}
void flight::calfuel()
{
if(dist<=1000)
fuel=500;
else if(dist>1000 && dist<=2000)
fuel=1100;
else if(dist>2000 && dist<=3000)
fuel=2200;
else if(dist>3000)
{
cout<<"The flight cannot travel such huge distances, try 'via' flights.\n";
fuel=0;
}
}
int main()
{
flight f1;
f1.getdata();
cout<<"\nPress any key to continue...";
getch();
system("cls");
f1.outdata();
cout<<"\nPress any key to exit.";
getch();
return 0;
}
P.S - I tried even tried this :
#include <string>
string dest; //in the class; private: section
getline(cin, dest);
OUTPUT IMAGE :