twoarg.cpp 752 B

1234567891011121314151617181920212223242526272829303132
  1. // twoarg.cpp -- a function with 2 arguments
  2. #include <iostream>
  3. using namespace std;
  4. void n_chars(char, int);
  5. int main()
  6. {
  7. int times;
  8. char ch;
  9. cout << "Enter a character: ";
  10. cin >> ch;
  11. while (ch != 'q') // q to quit
  12. {
  13. cout << "Enter an integer: ";
  14. cin >> times;
  15. n_chars(ch, times); // function with two arguments
  16. cout << "\nEnter another character or press the"
  17. " q-key to quit: ";
  18. cin >> ch;
  19. }
  20. cout << "The value of times is " << times << ".\n";
  21. cout << "Bye\n";
  22. // cin.get();
  23. // cin.get();
  24. return 0;
  25. }
  26. void n_chars(char c, int n) // displays c n times
  27. {
  28. while (n-- > 0) // continue until n reaches 0
  29. cout << c;
  30. }