how can i change two ints with one cin?

like the title says, how can I change two ints with a single input? In my program there's two types of vehicles and they have different prices, each vehicle has a different rate added per foot if it's length exceeds 20 ft.

I was thinking it would go something like this but it only changes x's value
1
2
3
4
5
int x
int y

  cout << "What is the length of the vehicle in feet?";
  cin >> x & y;
i found out this works
1
2
3
4
5
cout << "What is the length of the vehicle in feet?" << endl;
		cin >> c;
		y = c;
		x = c;
		cout << x <<"  "<< y<<endl;


not sure if the best way but it work for now
You can make use of references.
1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main()
{
    int c{ 0 };
    int& x{ c }; int& y{ c };
    std::cout << "What is the length of the vehicle in feet?\n";
    std::cin >> c;
    std::cout << "x = " << x << "\ty = " << y << "\n";
}


What is the length of the vehicle in feet?
12
x = 12	y = 12
Last edited on
If you want to enter two variables this way is simple enough

1
2
3
4
5
int x;
int y;

  cout << "What is the length of the vehicle in feet?";
  cin >> x >> y;
Last edited on
Topic archived. No new replies allowed.