Suppose I have 3 int variable named var1,var2,var3 how do i cin this using forloop and then cout the inputted data | Sololearn: Learn to code for FREE!

0

Suppose I have 3 int variable named var1,var2,var3 how do i cin this using forloop and then cout the inputted data

For loop c++

12/13/2019 1:09:23 AM

Kruuk

1 Answer

New Answer

+1

Well if you already have 3 variables just do std::cin >> var1 >> var2 >> var3; std::cout << var1 << var2 << var3; but if you want a for loop without arrays or anything helpful [UNTESTED] for (int i=0; i < 3; i++){ switch(i){ case 0: std::cin >> var1; break case 1: std::cin >> var 2; break; case 2: std::cin >> var3; break; default: break; } } // Bad and cout the same as above