Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Contributions to C::B => Topic started by: rip111buddy on December 20, 2011, 06:29:34 PM

Title: String Input gets Bypassed HELP
Post by: rip111buddy on December 20, 2011, 06:29:34 PM
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 : (http://i39.tinypic.com/2uomie1.png)

Title: Re: String Input gets Bypassed HELP
Post by: Alpha on December 20, 2011, 07:09:24 PM
You are both in the wrong forums and definitely the wrong subforums (notice C::B DEVELOPMENT STRICTLY!).
Try someplace like http://www.cplusplus.com/forum/ (http://www.cplusplus.com/forum/)
Title: Re: String Input gets Bypassed HELP
Post by: Jenna on December 20, 2011, 07:19:28 PM
You violate our forum rules (http://forums.next.codeblocks.org/index.php/topic,9996.0.html).
When registering here, you accepted to respect the rules.

Topic locked !