473,506 Members | 13,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program help

32 New Member
I have most of the program I just need help with A-C


Translate the following algorthm into a main function for a C++ program.

1. Read an integer number- N
2. While N is not greater than zero
2.1 Read another number - N.
3. Set the product to one.
4. For each value 1 to N
4.1 product = product * value
5. Print the product


Write functions for the following.
A. Write steps 1 and 2 above as a function which reads and returns the value of N that is read.






B. Write steps 3 and 4 as a function that has N as the value parameter and computes the factorial of N.







C. Rewrite the main function using the functions in A and B.
#include <iostream>
using namespace std;

int funct (int n){
int p;
cout << "Enter a number:";
cin >> n;
p = n;
return p;
}


int main()
{
int n;

cout << "Enter a number:";
cin >> n;

while (n<=0)
{
cout << "Please a positive number";
cin >> n;
}

int product = 1;
for(int x = 1; x<=n; x++)
{
product = product*x;
}
cout << product << endl;

cout << funct (n) << endl;



return 0;
}
Jan 25 '07 #1
1 959
RedSon
5,000 Recognized Expert Expert
I have most of the program I just need help with A-C


Translate the following algorthm into a main function for a C++ program.

1. Read an integer number- N
2. While N is not greater than zero
2.1 Read another number - N.
3. Set the product to one.
4. For each value 1 to N
4.1 product = product * value
5. Print the product


Write functions for the following.
A. Write steps 1 and 2 above as a function which reads and returns the value of N that is read.



int read();


B. Write steps 3 and 4 as a function that has N as the value parameter and computes the factorial of N.


int factorial(int N);




C. Rewrite the main function using the functions in A and B.
#include <iostream>
using namespace std;

int funct (int n){
int p;
cout << "Enter a number:";
cin >> n;
p = n;
return p;
}


int main()
{
int n;

cout << "Enter a number:";
cin >> n;

while (n<=0)
{
cout << "Please a positive number";
cin >> n;
}

int product = 1;
for(int x = 1; x<=n; x++)
{
product = product*x;
}
cout << product << endl;

cout << funct (n) << endl;



return 0;
}
There I did the first two for you, you can do the rest.
Jan 25 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
8484
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
2
1772
by: stanlo | last post by:
Hallo to everyone, i am just begining to learn c++ even though i did pascal when i studied mathematics in the univesity.i just took on my self a project which writing a c++ program which does...
7
3250
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
2530
by: Willing 2 Learn | last post by:
Below is a program I did to recognize a Finite State Automata for ASCII (J+H)*. I got that one working but im having trouble getting the NFA program to work. I really desperately need help! My...
66
5279
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
12
2792
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if...
21
2512
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
0
1370
by: ashishbathini | last post by:
Hi guys here is my problem ... this is the source code I Have , honestly I hav no idea how it works bcos its too complicated for me .... but my problem is ... i hav a freq comonent in it .......
9
2981
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.