I need TO HELP NOW PLEASE

Q1
recursive function that receives an integer x and prints the alternating alphabetic characters Write a main function to test the function;

ENTER NUMBER : 4

A C E G

Q#2
Define a void function that finds the smallest value in the array and number of its occurrences. Also, it finds the largest value in the array and number of its occurrences.



ENTER 4 NUMBERS:
1 12 5 41 41

THE BIGGEST IS 41 AND IT OCCURS 2 TIME
THE SMALLEST IS 1 AND IT OCCURS 1 TIME
Last edited on
There are many ways to do that.
For example a while loop like this in your main function:

1
2
3
4
5
6
7
8
9
string some_string;
while(true) {
cin >> some_string;
    if (some_string == "exit") return;
    if (some_string == "power program")
        //call the PowerProgram function
    else
        //call the SumProgram function
}
I decided to go about doing this and this is what I ended up with
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
#include <iostream>
#include <math.h>

using namespace std;

int sumprog()
{
	int counter = 1;
	int n;
	int result = 0;
	cout << string(100, '\n');
	cout << "Please input n: ";
	cin >> n;
	int numbarray[n];
	while(counter != n+1)
	{
		numbarray[counter] = counter;
		cout << numbarray[counter];
		counter++;
	}
	counter = 1;
	while(counter < n+1)
	{
		result = result + numbarray[counter];
		cout << result << endl;
		counter++;
	}
	return result;
}

int powerprog()
{
	double x;
	double n;
	cout << string(100, '\n');
	cout << "Please input base number: ";
	cin >> x;
	cout << "\nPlease input secondary number: ";
	cin >> n;
	return pow(x, n);
}

void menu()
{
	bool exit = false;
	int option;
	while(exit != true) 
	{
		cout << "1. Power program 2. Sum program 3. Exit\n";
		cin >> option;
		if(option == 1)
		{
			int answer = powerprog();
			cout << string(100, '\n');
			cout << "The value returned was: " << answer << endl; 
		}
		else if(option == 2)
		{
			int answer = sumprog();
			cout << string(100, '\n');
			cout << "The result is: " << answer << endl;
		}
		else if(option == 3)
		{
			cout << "Bye :)";
			exit = true;
	    }
	}

}

int main() 
{
	menu();
	return 0;
}
Last edited on
Thank you to help me
and I have another question
please help me


question#1:
Write a C++ program that reads integers until 0 is entered .For each entered number, the program checks whether it is an odd or an even number and print an appropriate message . Use IsEven() function that receives an integer and return true if it's even , otherwise it returns false.

The sumple run is:
Enter set of numbers and 0 to stop .
12
12 is an even number.
11
11 is an odd number.
3
3 is an odd number.
0
Press any key to continue ...


question #2:

Write a C++ function that displays a triangle pattern as shown below, based on the received size. . Write an appropriate main program to examine this function.
The sample run is:

Enter the size :10
**********
*********
********
*******
******
*****
****
***
**
*
Press any key to continue ...


The teacher want a brief answer
if you can
and thank you for help me again *_*
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
using namespace std;


int main ()
{
    int n;
    cout<<"enter no:";
    cin>>n;
    while(n){
        if(n%2){
                cout<<n<<" is odd"<<endl;
        }else{
        cout<<n<<" is even"<<endl;
        }
 cout<<"enter no:";
    cin>>n;
    }


  return 0;
}
Thank you to hep me
What about last question ?
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
#include <iostream>

using namespace std;

void pyramid(int size)
{
	int counter = size;
	int pyramidsize = size;
	while(pyramidsize != 0)
	{
		if(counter != 1)
		{
			cout << "*";
			counter--;
		}
		else
		{
			cout << "*\n";
			pyramidsize--;
			counter = pyramidsize;
		}
	}
}

int main()
{
	int action = 1;
	while(action != 0)
	{
		cout << "Please enter size(0 to exit): ";
		cin >> action;
		pyramid(action);
	}
}
Thank you.
HELP ME PLEASE
I wrote code but, I dont know where is the error at yet.
I want run
lesson about function and call the funcion.

Question:
Write a c++ program that keeps displaying the following menu driven:
• Power Program ( xn ) : define a function that returns x powered to n .
• Sum Program ( sum = 1+ 2+ 3+ 4+ … + n ) ) : define a function that returns the sum of the integers between 1 and n.
• Exit : display Bye message.
The program should stop when the user selects the exit option.

- sumple run:
Please select one of the following :
1-Power Program.
2-Sum Program.
3-Exit
your choice? 1

Enter an Integer?3
Enter the Wanted Power?2
3 Power 2 = 9

Please select one of the following :
1-Power Program.
2-Sum Program.
3-Exit
your choice? 2

Enter an Integer?4
Sum=10

Please select one of the following :
1-Power Program.
2-Sum Program.
3-Exit
your choice? 3

Bye
Press any key to continue ...

my cdoe Is:


#include<iostream>
#include<string>
using namespace std;
int PowerProgram(int x , int n)
{
int y , z;
return x*n;
}
string SumProgram(int s)
{

int sum;
sum=sum++;
}


int main()
{
int cho;
cout<<"Plese select one of the following :"<<endl;
cout<<"1-Power program.\n2-Sum program.\n3-Exit"<<endl;
cin>>cho;
string some_string;
while(true) {
cin >> some_string;
if (some_string == "exit") return;
if (some_string == "power program")
{
PowerProgram;
}
else
SumProgram;
}

return 0;
}



and this question also:
Write a C++ program that reads integers until 0 is entered .For each entered number, the program checks whether it is an odd or an even number and print an appropriate message . Use IsEven() function that receives an integer and return true if it's even , otherwise it returns false.

sumple run:

Enter set of numbers and 0 to stop .
12
12 is an even number.
11
11 is an odd number.
3
3 is an odd number.
0
Press any key to continue ...

Last edited on
You should put your code in [ code ] so it's easier to read. Also, you should probably put your functions above main().
ok. I know but, when I put the function above main How can I make ( call ) for function? I do not understand it.
help me please .
Last edited on
I... Think it would be best if you looked at the tutorials on this site. I'm also not certain as to why sumprog() is a string? Nor does it print a value...
Lol my god stop enabling this man. He has no idea what he is doing.
q1 -- weite function that receives an integer and prints the equivalent representation in binary system. The received integer must be a positive number
use call by value or by refrence
you can use global or local values



please help me.
Last edited on
you know what?

You better spend a few hours learning the basics of software development, just google "C++ Tutorial" or something like that, then you'll be able to solve these problems in no time ;)
write function that receives int and prints the equivalent representation in binary system. The received int must be a positive number smaller than 100;

my code with error
help me please;


and how can i write this function?
receives the kilowatt-hours used and returns the charge for electricity for a customer. Electric charges are 0.95 S.R per kilowatt.
Last edited on
HELP ME , PLEASE
HELP ME , PLEASE
HELP ME , PLEASE
HELP ME , PLEASE

how can I calculate this :

finds the smallest value in the array and number of its occurrences. Also, it finds the largest value in the array and number of its occurrences.

Last edited on
Hi

Here is another version for the even or odd program.

#include <iostream>

using namespace std;


bool even(int n) {
if((n % 2) == 0)
return true;
else
return false;
}
int main()
{
int x;

cout << "Please enter a number(0 to stop): ";
cin >> x;

while(x != 0) {

if(even(x))
cout << x << " is even number." << endl;
else
cout << x << " is odd number." << endl;

cout << "Please enter a number(0 to stop): ";
cin >> x;

}

return 0;
}
Topic archived. No new replies allowed.