dina
dina

Reputation: 45

Cpp input until ctrl+d

How to pass last four values from entry into function distance as arguments? For example if I enter values

2 6

1 2

4 8

I want the compiler to pick up last four values 1,2,4 and 8 and print (1,2) (4,8) =6.7 How to pick them up from buffer?

Thanks

#include <iostream>
#include <cmath>
#include <string>

struct point{

  int x1,x2;
  int y1,y2;



};

double distance(int x1,int y1,int x2,int y2){

  double d=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
  
   return (int)(d*10.0)/10.0;


}

int main(){

point a;


while(std::cin>>a.x1>>a.y1>>a.x2>>a.y2){


std::cout<<"Distance: "<< distance(a.x1,a.y1,a.x2,a.y2);

}
return 0;
}
                                                                                 
                                                                                 

Upvotes: 0

Views: 62

Answers (1)

Thomas Matthews
Thomas Matthews

Reputation: 57718

Try reading the first row and ignoring it:

std::string text_to_ignore;
std::getline(std::cin, text_to_ignore);
std::cin >> a.x1 >> a.y1 >> a.x2 >> a.y2;

Upvotes: 1

Related Questions