need help on where to start

0. The main program starts by calling a function named introduction which prints out a description of what the program will do. This function is called just once.

This function is not sent any parameters, and it does not return a value. It prints several lines of output explaining what the program does (it should also say how to end the set of data—see step 4). The function should print your name.


1. Then the main program asks the user to type in an integer value which the main program calls n; n could be positive, negative, or zero (see step 4). The main program prints the number n after it is read in.


2. The main program calls a function named isiteven, sending it the integer value n as a parameter. The function determines whether or not n is even, sending the answer back to main. (Hint: if n is even, the remainder when n is divided by 2 is 0; this works for all even numbers, including 0.) You may return an integer (like 0 or 1) to represent even or odd, or return a character (like ‘e’ or ‘o’).

The main program prints the answer returned together with a message. For example, if you send 6, the function determines it is even, and the main program prints that 6 is an even number.

3a. If n is even, the main program calls a function named sumevensquares, sending n to the function as a parameter. The function computes the sum of the first n even squares (see below). The function returns this sum to the main program. Then the main program prints a message giving n and the sum of the first n even squares.

For example, if you send 4, then the sum of the first 4 even squares is 2*2 + 4*4 + 6*6 + 8*8 = 4+16+36+64 = 120.

Note the function computes the sum of the first n even squares- this will be: 2*2 + 4*4 + 6*6 + ... + (2n)*(2n), where n is the parameter value sent to the function.

b. However, if n is odd, the main program calls a function named sumoddnumbers, sending it n. The function computes the sum of the first n odd numbers (see below). The function returns this sum to the main program. Then the main program prints a message giving n and the sum of the first n odd numbers.

For example, if you send 3, then the sum of the first 3 odd numbers is 1 + 3 + 5 = 9. For n=5, it is 1+3+5+7+9 = 25, etc.

Note the function computes the sum of the first n odd numbers- this will be: 1 + 3 + 5 + ... + (2n-1), where n is the parameter value sent to the function.

In either case, the main program calls one of two functions to compute a sum of terms, then prints the function's answer.


4. After calling a function to compute the appropriate sum and printing the result, the main program will skip a few lines and go back to step 1 (not step 0). At step 1, if the user types in
a negative value, the program will go to step 5.


5. At the end, print how many data values were entered and processed. (Make sure that this number is at least 8.)


DATA: Type in a total of at least 8 data values. Have at least four even numbers (make sure 0 is one of the even numbers) and four odd numbers; intersperse the values: odd, then 2 evens, then odd, etc. Have one value of each type that is between 10 and 20 (and the rest smaller).

You will be judged on the quality of your data.

STYLE: Be sure that each function has a good comment explaining two things: exactly what parameter(s) the function will receive, and exactly what the function will do (and if it returns an answer or prints). Mention parameters by name in the comment.


OUTPUT: Here is some sample output (ignoring the introduction):

the original integer is 5
5 is an odd number
the sum of the first 5 odd numbers is 25

the original integer is 4
4 is an even number
the sum of the first 4 even numbers is 120

OPTIONAL: If the user enters a negative value, say this is no good, ask the user to type in a new value that is good (greater than or equal to 0). The program continues until the user enters a special value (not just any negative value) that signals the end.


this is what i have so far:

#include <iostream>
#include <cmath>
using namespace std;
int main()
{int introduction; int n; int isiteven; int sumevensquares;
cout>> This program is designed to cumpute negative or postive numbers>>endl;
}
cout<<”Please type in an integer value”<<endl;
cin>> n
cout<< “n”
Start with "Hello, world" and get each piece to work, one at a time. Don't move to part 1 until part 0 works.
Start from a known, good place so that you know you can compile and run a program.
"Hello, world"
1
2
3
4
5
6
#include <iostream>

int main()
{
    std::cout << "Hello, world";
}


On the next iteration of your program, introduce some small change that still yields a valid result. For example, printing something by calling a function instead of printing it directly.
"Hello, world", with function call
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

void printMessage()
{
    std::cout << "Hello, world";
    return;
}

int main()
{
    printMessage();
}

From this code alone, you should be able to make a few changes to satisfy requirement 0 of your assignment.
Last edited on
Here you go buddy :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cmath>
using namespace std;

int isiteven(int);
int sumevensquares(int);
int sumoddnumbers(int);

int main()
{
	int n;

	cout << "Enter an integer: ";
	cin >> n;

	if (isiteven(n) == 0)
	{
		cout << n << " is an even number" << endl;
		cout << "Sum of the first " << n << " even numbers squared: " << sumevensquares(n) << endl;
	}
	else
	{
		cout << n << " is an odd number";
		cout << "Sum of the first " << n << " odd numbers: " << sumoddnumbers(n) << endl;
	}
	system("pause");
}
int isiteven(int x)
{
	if (x % 2 == 0 || x == 0)
		return 0;
}
int sumevensquares(int x)
{
	int sum = 0;
	int a = 2;
	for (int i = 0; i < x; i++)
	{
		sum += pow(a, 2.0);
		a += 2;
	}
	return sum;
}
int sumoddnumbers(int x)
{
	int sum = 0;
	int a = 1;
	for (int i = 0; i < x; i++)
	{
		sum += a;
		a += 2;
	}
	return sum;
}
Topic archived. No new replies allowed.