Hopefully the additional numbers on the left don't cause confusion. They are automatically put into my program as I write it. If it is a problem, let me know and let me know how to change it. Thanks:
In this exercise, you will be writing and using three functions. The first counts from 0
to the parameter and prints the numbers out in a single line. The second function
counts down to 0 from the parameter. The last function should count between the
two parameters. If the first number is smaller than the second number, the function
should count up. If the first number is larger, the function should count down.
Once all three functions are written, write a main function that prompts the user for
two positive numbers, then uses the first for the count up and count down functions
and both numbers for the count between function. After doing this once, the program
should ask the user if they would like to quit or re-run the program.
#include<iostream>
8
9 using namespace std;
10
11 int down ( int a ) {
12 int z;
13
14 for ( z = 0; z <= a; z++ ) {
15 cout << z;
16 return (z);
17 }
18 }
19 int up ( int a){
20 int z;
21
22 for ( z = a; z >= 0; z-- ){
23 cout << z;
24 return (z);
25 }
26 }
27 int count ( int a, int B)/>{
28 int z;
29
30 if ( a < b ){
31 for ( z = a; z <= b; z++){
32 cout << z;
33 return (z);
34 }
35 }
36 else if ( a > b ){
37 for ( z = a; z >= b; z--){
38 cout << z;
39 return (z);
40 }
41 }
42 }
43 int main (){
44 char answer;
45
46 cout << "Do you want to continue (Y or N)?" << endl;
47 cin >> answer;
48
49 if ( answer == 'N' || answer == 'n') return 0;
50
51 do{
52 int a, b, upUp, downDown, countCount;
53
54 cout << "Enter one positive number: " << endl;
55 cin >> a;
56 cout << "Enter a second positive number: " << endl;
57 cin >> b;
58 downDown = down (a);
59 cout << downDown << endl;
60 upUp = up (a);
61 cout << upUp << endl;
62 countCount = count(a, B)/>;
63 cout << countCount << endl;
64 cout << "Do you wan to continue (Y or N)?" << endl;
65 cin >> answer;
66 if ( answer == 'N' || 'n') return 0;
67 }
68
69 while ( answer!= 'N' || 'n' );
70 return 0;
71 }

New Topic/Question
This topic is locked


MultiQuote



|