help with non void functions with an argument

i have a C++ project due at 5 p.m. pacific time today. my teacher did a poor job at explaining and missed telling us how to do part of the assignment. that being said my teacher is ruthless. my code is all over the place and this is my last resort.

my assignment is to write a program using VOID FUNCTIONS WITH AN ARGUMENT.
*I need one non-void function with an argument to generate the first 15 numbers greater than 500, another non-void function with an argument to generate the first 15 perfect squares that are greater than 500. Last, they need to be in columns next to each other.* also i cant use x,y, coordinates to align them. i must create a for loop with the

if a miracle happens and someone does it for me i will send them $20 in the mail.

these are some notes from examples in the class. i just don't know how to do it with non void functions with an argument.

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// March 4 - 6 Notes//


#include "stdafx.h"

#include <iostream>
#include <iomanip>

using namespace std;

void ClearTheScreen();
void NormalTermination();
void FunctionOne(int A);
void FunctionTwo(int A);
void FunctionTre(int A);
void Heading();
void FunctionSupervisor();

int main()
{
	ClearTheScreen();
	Heading();
	FunctionSupervisor();

	NormalTermination();

	return 0;
}

void ClearTheScreen()
{
	system("cls");
}
void NormalTermination()
{
	cout << "\n\n\n\n\n\t\t\t";
}
void Heading()
{
	cout << "\t\t\tFirst   Second      Third\n\n";
}
void FunctionOne(int A)
{
	cout << "\t\t\t  " << A+1;
}
void FunctionTwo(int A)
{
	cout << "\t\  " << A+2;
}
void FunctionTre(int A)
{
	cout << "\t      " << A+3;
}
void FunctionSupervisor() // This shows how to put the functions in columns //
{
	int k;
	for ( k = 0; k < 5; k++)
	{
		FunctionOne(k);
		FunctionTwo(k); 
		FunctionTre(k);
		cout << "\n";
	}
}


// March 6 coverage

// March6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

// non-void function with NO Argument
// non-void function with AN argument

double SquareRootOne();
double SquareRootTwo(double A);
bool IsItPrime(int A);

int main()
{
//    SquareRoot();
	int A;
/*
	cout << "\n\t\tPlease give me a pathethic number : ";
	cin >> A;

	cout << "\n\t\tThe square root of " << A << " is = " << SquareRootTwo(A);

*/
	cout << "\n\t\tGive me a number to test for PRIME : ";
	cin >> A;
	
	if ( IsItPrime(A) )
	{
		cout << "\n\t\tThe number " << A << " IS PRIME";
	}
	else
	{
		cout << "\n\t\tThe number " << A << " is NOT PRIME";
	}
	cout << "\n\n\n\n\t\t\t";
	return 0;
}

double SquareRoot()
{
	int A;

	cout << "\n\t\tPlease give me a pathethic number : ";
	cin >> A;

	cout << "\n\t\tThe square root of " << A << " is = " << sqrt(A*1.0);

	return  -3;
}

// As much as possible, refrain from using a non-void function WITHOUT AN ARGUMENT:

double SquareRootTwo(double A)
{
	return sqrt(A);
}

bool IsItPrime(int A) // prime //
{
	int k;
	bool Lahop;

	Lahop = true;

	for ( k = 0; k < sqrt(A*1.0); k++)
	{
        if ( A % (k+2) == 0 )
		{
			Lahop = false;
		}
	}
	return Lahop;
}



Last edited on
I'm having a little trouble understanding exactly what you need here.

Rudy Ortiz wrote:
I need one non-void function with an argument to generate the first 15 numbers greater than 500, another non-void function with an argument to generate the first 15 perfect squares that are greater than 500.

Should the first one be prime numbers here? The 'first 15 numbers greater than 500' seems a little easy for an assignment.

There seems to be a core understanding of arguments and returns types here, though. Do you understand each of those and their uses?
yeah, sorry i meant the first 15 Prime numbers greater than 500.
Last edited on
no i do not understand non void functions with arguments. if you could do it for me before class starts i would appreciate it and would literally mail you $20. my teacher is a no mercy type guy.
Last edited on
Definitely not going to do any assignments for you.

This post just transitioned from a 'help me understand' post to a 'do my homework' post. For that reason, I've got nothing to offer you.
I realize that your assignment was due about two hours ago or so, but you still might like a quick explanation of "non void functions with arguments".

each function needs to have a return type.
each function can take parameters / arguments.

The two concepts are completely decoupled from one-another.

Note: There is a small difference between parameters and arguments, but it's nothing a beginner should have to worry about. In a sense, it's merely a naming convention.

When a function terminates, it returns something to the calling function / process. The function return type is what determines what the type of the thing that's being returned is.

If a function has a void return type, that means it doesn't return anything. If a function is non-void, it has to return something. If a function is void, it cannot return something.

Parameters / arguments are things you pass into the function. They can affect the flow or outcome of the function. For instance, depending on an argument, the value that a function returns could be different.

Here's an example of a function with a void return type (returns nothing), and no parameters / arguments:

1
2
3
void printHello() {
	std::cout << "Hello" << std::endl;
}



Here's an example of a function with an int return type (returns an integer), and no parameters / arguments:

1
2
3
int retThreePlusFive() {
	return 3 + 5;
}



Here's an example of a function with a void return type (returns nothing), and takes one string parameter / argument:

1
2
3
void printString(std::string string) {
	std::cout << string << std::endl;
}



Here's an example of a function with an int return type (returns an int), and takes two int parameters / arguments:

1
2
3
void add(int a, int b) {
	return a + b;
}
Last edited on
Topic archived. No new replies allowed.