473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

please check the coding for me..

12
Question...

An approximate value of pi can be calculated usong the series given below:

Pi=4[1-1/3+1/5-1/7+1/9…+((-1)n)/(2n+1)]


((-1)n)=n is a power for-1(for your information)

Write a C++ program to calculate the approximate value of pi using this series.The program takes an input n that determines the number of terms in the approximation of value of pi and outputs the approximation.Includes a loop that allows the users to repeat this calculation for new values n until the user says she or he wants to end the program.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream> 
  2. using namespace std;
  3.  
  4. void prime_num(int);
  5. int main()
  6. {
  7.  int retry;
  8.  
  9.    do
  10.    {  
  11.       int x = 100;
  12.       prime_num(x);
  13.    }
  14.  
  15. void prime_num( int n)
  16. {
  17.    bool Prime=true;
  18.  
  19.    for ( int k = 3; k <= n; k++)
  20.    {
  21.       for ( int j = 2; j <= n; j++)
  22.       {
  23.          if ( k!=j &&k % j == 0 )
  24.          {
  25.             Prime=false;
  26.             break; // stop looping
  27.          }
  28.       }
  29.       if (Prime)
  30.       {                    
  31.          cout << " do you want to repeat the process?(Yes/No)"\n";
  32.          cin >> retry;
  33.       } while ( retry='Y'|| retry='y')
  34.  
  35.       cout << "  Prime: " << k <<  ""; 
  36.    }
  37.    Prime = true; 
  38. }
  39.  
  40. }
this coding cannot give me an output n have many error.
Mar 14 '07 #1
8 4260
Banfa
9,065 Expert Mod 8TB
Interestingly you problem seems to be about calculating PI but the could you have posted appears to be code to find prime numbers.

May be you would like to

1. Read the Posting Guidelines particularly the part about posting coursework.

2. Post the code actually related to the problem, or post the problem actually related to the code.
Mar 14 '07 #2
yana
12
i'm sorry
the coding is for prime question
but there is no output

this is the question for the prime coding

Write a program that finds and prints all the numbers between 3 and 100.A prime number is a number such that one and itself are the only numbers that evenly divide it(eg.,3,5,7,11,13,17,.....)

one way to solve this problem is to use a doubly nested loop.The outer loop can iterate from 3 to 100 while the inner loop checks to see if the counter value for the outer loop is prime.one way to see if number n is prime is to loop from 2 to n-1 and if any of these numbers evenly divides n,then n cannot be prime.if none of the value from 2 to n-1 evenly divide n,then n must be prime.

can you help me??
I'm sorry to disturb you.

why the program no output?
is it false??
Mar 14 '07 #3
sicarie
4,677 Expert Mod 4TB
i'm sorry
the coding is for prime question
but there is no output

this is the question for the prime coding

Write a program that finds and prints all the numbers between 3 and 100.A prime number is a number such that one and itself are the only numbers that evenly divide it(eg.,3,5,7,11,13,17,.....)

one way to solve this problem is to use a doubly nested loop.The outer loop can iterate from 3 to 100 while the inner loop checks to see if the counter value for the outer loop is prime.one way to see if number n is prime is to loop from 2 to n-1 and if any of these numbers evenly divides n,then n cannot be prime.if none of the value from 2 to n-1 evenly divide n,then n must be prime.

can you help me??
I'm sorry to disturb you.

why the program no output?
is it false??
There is no outoput at all?
Mar 14 '07 #4
yana
12
what should i do to get the output?
it must have an output, isn't it?
Mar 14 '07 #5
Banfa
9,065 Expert Mod 8TB
Your posted code does not compile because you have defined the function prime_num inside the function main and C/C++ does not support nested function definitions.

You need to begin by moving prime_num outside main.
Mar 14 '07 #6
yana
12
Your posted code does not compile because you have defined the function prime_num inside the function main and C/C++ does not support nested function definitions.

You need to begin by moving prime_num outside main.
I move the prime_num already but it still cannot get the output.
There is no output at all.Please help me..
Mar 14 '07 #7
Banfa
9,065 Expert Mod 8TB
You code is such that your assertation that you have fixed the problem with location of prime_num in the posted code does not enable us to tell what the resulting code is as there were several other errors.
Mar 14 '07 #8
Ganon11
3,652 Expert 2GB
As Banfa said, there are countless errors in the posted code. Not only is prime_num defined inside main, but it is between the end bracket and the while () of your first loop. Also, the prime_num function is not finished - after you close the second if() statement, you continue with the while(). Rearrange the code to make sense, finish the main() and prime_num() functions, and then see if you are still getting bad output.
Mar 14 '07 #9

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

Similar topics

3
by: Jason | last post by:
hello, i am new to PHP, so go easy. I am using the examples in the book: PHP: Your Visual Blueprint For Creating Open Source, Server Side Content In the section where they talk about...
2
by: Rv5 | last post by:
Let me start out by saying this is actually c++ code, but I couldn't get anyone on the c++ newsgroup to respond, and Id really like opinions. The code works fine, so Im not looking for syntax...
11
by: Steve Clay | last post by:
I have a small C program for a college course. It is meant to encrypt and decrypt lower case letters and leave spaces as spaces. I can't get it to run properly as I think I have a problem in the...
5
by: Bharat Shetty | last post by:
project doubt 1) ping all defined machines in the network from time to time, and alert (by an indicator on a web page or screen) when some machine is down (2) periodically check HTTP and FTP...
4
by: Gary | last post by:
Hello, I'm hoping someone can shed some light on why my report does not output the same results as shown in preview mode, which is to move the position of a check box based on a field value (see...
9
by: silverchrono | last post by:
this is my first semester in C and im trying to figure out how to reset a counter. heres why im trying to do. void text() 59 printf("You can end entering the text by using '#'\n"); 60 int...
5
kirubagari
by: kirubagari | last post by:
I want to check the arrangement of data in this order from byte 49 to mFile size(END OF FILE). 04 FF _ _ _ _ _04 FF _ _ _ _ 04 FF _ _. _ __ 04 FF _ _ _ _ 04 FF _ _ _ _ 04 FF Actually the values...
0
by: magicofureyes | last post by:
Hello Guys im a just a new user and i dnt knw much abt Xml i want to upload a new template in Blogger so got some free coding but when i save this code in Blogger template it say '''' Your...
3
by: phanimadhav | last post by:
Hi, i am working on the coding part which is based on jsp/html.As im fresher i am facing some problems with the code.so,can u please guide me..This is the error which i ve got...please have a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.