Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. var first , second int
  2. // var second int
  3.  
  4. _,err := fmt.Scanf("%d", &first)
  5. if err != nil {
  6.  
  7. fmt.Printf("%d is not a valid number", first)
  8. os.Exit(1)
  9. } else {
  10. fmt.Printf("%d", first)
  11. }
  12. fmt.Println(" \nPlease enter the second integer ")
  13. _,err2 := fmt.Scanf("%d", &second)
  14.  
  15. if err2 != nil {
  16. fmt.Println("second number is not a valid numnber , exiting the program")
  17.  
  18. os.Exit(1)
  19. }
  20.  
  21. sum := first + second
  22. fmt.Printf("Sum of %d and %d is %d" , first,second ,sum)
  23.  
  24.  
  25.  
  26. }
  27.  
  28. Output
  29.  
  30. Please enter the first integer
  31. 4.5
  32. 4
  33. Please enter the second integer
  34. Sum of 4 and 5 is 9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement