SHARE
TWEET

Untitled

a guest Oct 12th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Uppgift 3 (15p)
  2. a. (6p) Rita ett flödesdiagram där programmet tar emot heltal tills användaren skriver in ett
  3. minustal eller har skrivit in totalt 10 heltal. Välj en loop som passar till det här problemet.
  4. b. (9p) Gör ett flödesdiagram som representerar koden nedanför.
  5. #include <iostream>
  6. using namespace std;
  7. int sumNumbers(int num1, int num2) {
  8. return num1+num2;
  9. }
  10. bool goAgain()
  11. {
  12. char again;
  13. while (true)
  14. {
  15. cout << "Do you want to add two numbers? (y/n)" << endl;
  16. cin >> again;
  17. if (again == 'y' || again == 'Y')
  18. {
  19. return true;
  20. }
  21. else if (again == 'n' || again == 'N')
  22. {
  23. return false;
  24. }
  25. else
  26. {
  27. cout << "Please answer yes (y) or no (n)" << endl;
  28. }
  29. }
  30. }
  31. int main()
  32. {
  33. while (goAgain())
  34. {
  35. int number1 = 0;
  36. int number2 = 0;
  37. cout << "Number one: ";
  38. cin >> number1;
  39. cout << "Number two: ";
  40. cin >> number2;
  41. cout << sumNumbers(number1, number2) << endl;
  42. }
  43.  return 0;
  44. }
RAW Paste Data
Top