0

using scanf instead of cin for multiple inputs

1. is it better to use scanf and printf instead of cin and cout? advantages of scanf and printf? 2. how to i get a pop-box in sololearn for the user to enter values with scanf or cin ? 3. is it possible to consolidate multiple inputs into scanf function or cin? #include <iostream> #include "stdio.h" using namespace std; int main() { int a, b; printf("enter a number! \n"); scanf("%d %d ", &a &b); int sum=a+b; printf("The value sum is %d\n", sum); //current output:The value sum is 2147344384 without the user being prompted to enter values for a and b. return 0; } Thank you, i appreciate your assistance

2nd Aug 2017, 4:22 PM
Mich
Mich - avatar
4 Respuestas
+ 8
cin >> a >> b; Split multiple input into different lines, e.g. 3 4
2nd Aug 2017, 5:29 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
2. it is not possible here
2nd Aug 2017, 5:32 PM
jay
jay - avatar
+ 3
printf and scanf is C Style syntax. It's better to use C++ syntax (cout, cin) if you're learning C++.
2nd Aug 2017, 5:03 PM
Brandon
Brandon - avatar
0
thank you guys
2nd Aug 2017, 6:09 PM
Mich
Mich - avatar