C :: Calculate Value Of PI With The Accuracy (EPS) Given By User

May 23, 2013

I have to calculate the value of PI with the accuracy (eps) given by the user. I started with this but I just got stuck now, I don't know what is going on with the code or why does it get stuck in the second iteration...

PHP Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){    
float eps=0.000001; 

[Code] ....

View 4 Replies


ADVERTISEMENT

C/C++ :: Program That Calculate PI Based On User Input For Accuracy?

May 24, 2014

I am trying to create a program that will calculate pi based on a user input for accuracy. If the user input .3 then when the leibniz infinite sum value at a particular i becomes less then the input of .3 then the loop will exit.

I have looked at a number of examples on the internet but I feel lost. I have put together working code that will infinitely output sums but I need the loop to stop when the sum value is less then the accuracy value.

My question is what is wrong with my while loop, why will it only give me infinite summations? How do I make it so that the loop will exit when my accuracy input is greater then the sum?

int main () {
double accuracy;
cout<<"Give an accurate number." << flush;//looks nice
cin>>accuracy;
int d;//initialize denominator
double pi = 0.0;
while(accuracy < d){

[Code]...

View 8 Replies View Related

C++ :: Compiler Optimization And Num Accuracy?

Jun 11, 2014

I could not find anything I could understand on this, so I have heard that -O3 option may reduce the numerical accuracy of doubles. Is this true?

View 11 Replies View Related

C++ :: Calculate Sum Of Integer And Display To User

Mar 4, 2014

A problem that lets the user enter any positive integer, but you do not have to check for this, and then calculates the sum of the digits and displays this to user. For example, if user enters 14503, the outputted sum of the digits would be 13.

Here is my program

#include <iostream>
int main(void) {
int integer, sum=0;
while(integer) {
sum += integer % 10;
integer /= 10;
} cout << "The sum of the integers numbers is " <<sum;
return 0;
}

View 5 Replies View Related

C/C++ :: Calculate Result Of 2 Numbers That User Entered

Oct 29, 2012

In this exercise, write a rational number calculator that ask the user to enter two rational number:

a/b + c/d

and produce the result:

(ad+bc)/bd

View 10 Replies View Related

C++ :: Repeat A Question Over And Over And Calculate Total When User Wants To Quit

Feb 27, 2014

Write a program which is used to calculate GPA based on the grades from different courses Input by the user. User should be able to enter as many course unless they choose to quit. Once the user has completed entering the data, the program should be able to provide a feedback on the GPA. Where A=4, B=3, C=2, D=1.

View 1 Replies View Related

C++ :: Calculate GPA - Divide Depending On How Many Times User Inputs A Value

Feb 27, 2014

For example, to calculate GPA, we add all the grade point of a course and divide by the number of courses we are taking. How do I create a program in such a way that when the user enters grade point for two courses, it will add the grade points for the two course and divide by 2. And if another user enters grade points for six courses, it adds the grade points and divides by 6.

View 2 Replies View Related

C/C++ :: Calculate Percentage Of Even Numbers Entered By User In Array

Nov 18, 2014

exercise in c: write a program which calculates % of even numbers entered by a user in an array;

1) check if user hasn't entered float value; if has issue warning;
2) give the option for user to press "stop" to exit program any time.

int c,sk[100],i,sum1=0, sum2=0, rel;
printf ("How many numbers will you enter?
");
scanf ("%d", &c);
printf ("Enter %d numbers (to exit program press - stop)
", c);

[Code] ....

View 1 Replies View Related

Visual C++ :: Program That Take Input From A User And Calculate It In A Do While Loop

May 15, 2013

I'm trying to create a program that will take input from a user and calculate it in a do-while loop. The program does the calculation but the answer is wrong. The loop also doesn't work. The purpose of the program is to see how much an item will cost after a discount is taken off and tax is added.

#include <iostream>
#include <cmath>
using namespace std;
double original_cost;
double discount;
double tax;
double total;
char answer;

[Code]...

View 2 Replies View Related

C :: Calculate Different Measurements For A Cylinder - Width Modifier For End User Input

Sep 12, 2013

I have created a program to calculate different measurements for a cylinder. Anyways, the end user has to input 3 variables.

Enter the lower radius: 6
Enter the upper radius: 5
Enter slant height: 2.236

The numbers are what "End User" would input. But I need to make it look like this when said "End User inputs the numbers.

Enter the lower radius: 6
Enter the upper radius: 5
Enter slant height: 2.236

Here is what I have for it, but I don't know what to put where.

printf("
Enter the lower radius: ");
scanf("%f", &lower_rad);
printf("Enter the upper radius: ");
scanf("%f", &upper_rad);
printf("Enter slant height: ");
scanf("%f", &slant_h);

View 1 Replies View Related

C++ :: Calculate Approximate Age Of User Based On Current Date And Their Birthday

Nov 23, 2012

I have an extra credit project where I'm supposed to calculate an approximate the user's age based on the current date and their birthday. My problem is that I am not getting the proper date and time. C++ keeps giving me some random date. I looked up c++ time format on the internet because this is extra credit and not in my book.

I am currently using dev C++ 4.9.9.2. Here is my current code :

// included libraries
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <time.h>
#define cls system("cls")
#define pauseOutput system("pause")
void printM(int x);
void age(int m, int d, int y, int &yearAge, int &monthAge, int &dayAge);

[Code] ....

View 1 Replies View Related

C :: Calculate Cost For Production Of Open Top Cylinders - User Defined Functions

Feb 20, 2013

I have this program I wrote to calculate cost for the production of open top cylinders and how to translate it into user defined functions. Here are the user defined functions I need to use instruct() get_area() comp_area() and print_area_cost() so the program will be in 4 parts.

Code:
#include <stdio.h>
int main()
{double radius,height,cost,single,all;
float surface_area;
int count;
double pi=3.14159265;
printf("Enter the radius of the base in cm^2:

[Code] ......

View 2 Replies View Related

C++ :: User Input - Calculate Sum Of Only Positive Values While Ignoring Negative Numbers

Jun 19, 2014

So I have to make a program that allows the user to enter both positive and negative numbers and the program is suppose to calculate the sum of only the positive values while ignoring the negative values. Also it is to be a sentinel-controlled loop with a number ending the set of values.

View 4 Replies View Related

C :: Calculate Black Body Spectra Over User-entered Range Of Wavelength And Temperatures

Jul 29, 2013

I tried to write a code to calculate black body spectra over an user-entered range of wavelength and temperatures. The equation I'm trying to code is the second one this image (stolen from Wikipedia)The syntax to run it is bbgrid lambda_inic lambda_final temp_inic temp_final inc_T inc_lambda

where bbgrid is the name of the program, lambda_inic and lambda_final are the limits of the wavelenght range (in units of angstroms, 1A=10⁻⁰m), temp_inic and temp_final are the limits of the temperature range (in Kelvins) and inc_T and inc_lambda are the increments. What I want to do is, given the ranges of temperatures and wavelengths, to run the code over the lambdas and the temperatures.

The problem is that the behaviour of the intensities (what I'm calculating) is erratic. Sometimes it is highly positive, sometimes immensely negative and turning between those two. As an example of an output file, I'm getting things like this:

3100 1915076038
3110 -1233496775
3120 1741010116
3130 1229780625
3140 421722788
3150 -1874760945
3160 1654746252
3170 1062468321
3180 -795217626
3190 -1141129750
3200 -1570716956
3210 539385985

While I was trying to debug the code, I found the problem may reside in the exponential factor in the denominator. I wrote some lines to calculate and print on the screen only the exponential, and it was oscillating like crazy. The output file should produce curves like this:

Code:

#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<string.h>

[code]....

View 14 Replies View Related

C :: Generate A Program That Will Allow User To Enter Data For A Stock And Calculate Amount Of Stocks

Oct 5, 2013

Okay, so my assignment for my C class is to generate a program that will allow the user to enter data for a stock and calculate the amount of stocks that ended up being positive, negative, and neutral.I tried to do this using one stock, here is my code;

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

Code:

void main()
{
float Neg;
float incst;
float shrs;
float bpps;
float crnt;
float crntcst;
float yrfes;
float pft;
float tpft;
}

[code]....

View 6 Replies View Related

C++ :: Calculate User Birthday In Months / Days / Hours And Minutes From Today Date

Jul 24, 2014

The problem is that I need to figure out the user's birthday in months, days, hours, and minutes from today's date.

Here's what I have so far.

#include<iostream>
#include<cmath>
#include<ctime>
using namespace std;
int main() {
int todayDay, todayMonth, todayYear;
int birthDay, birthMonth, birthYear;

[Code] ....

I haven't initialized all the variables, yet. And it's very unfinished. I need to figure out how to convert years from the age into months only. And I need to figure out how to calculate the hours, seconds, and minutes.

View 3 Replies View Related

C++ :: User Input Data About Percentages To Calculate Final Grade - Addition Error?

Sep 15, 2014

I am trying to code a program that takes in user inputted data about percentages and using it to later on calculate a final grade. 4 percents are inputted, for Assignments, Midterm1, Midterm2, and Finals. If the percents dont add up to 1 (i tell the user to enter the decimal value) I set up and if statement to catch it and end the program. Except that if i type in

Assignments = .3
Midterm1 = .3
Midterm2 = .3
Finals = .1

the program doesn't recognize that they add up to 1. Heres the relevant portion of my code [URL] ....

Here's some examples of how it works [URL] ....

And heres what i dont understand [URL] ....

Why is it saying .3 + .3 + .3 + .1 != 1 when .1 + .3 + .3 + .3 == 1?

View 1 Replies View Related

C++ :: User Input Two Numbers - Calculate Square Root Then Roots Are Added Up To Return Sum

Aug 23, 2014

I have tried writing a code which takes two numbers from the user and calculates their square root then the roots are added up to return the sum. The program is coming out with loads of errors.

#include<iostream>
#include<cmath>
float main(){
using namespace std;
float m1,m2,m3,m4,m5;

[Code] ....

View 4 Replies View Related

C++ :: Store User Input In Array And Calculate Mean / Median And Mode - Bubble Sorting

Mar 26, 2014

I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.

View 5 Replies View Related

C++ :: User Array Size And Sorting User Input

Nov 1, 2014

I am making program that allows the user to determine how big the array size will be and then asks the user to make up numbers to fill the array. Every time run the program on Dev C++ it says "program has stopped working"

Heres My Code:

//Assignment 19 Program 2
#include <iostream>
using namespace std;
int main()

[Code].....

View 3 Replies View Related

C :: Calculate Approximate Value Of E

Jul 12, 2013

I'm trying to write a program to calculate an approximate value of e using the formula e = 1 + 1/1! + 1/2! + ....... 1/n!...However, I'm always getting nearly 2.291481 as answer.Here is my code :

Code:

//Approximate the value of e
#include <stdio.h>
int main(void) {
int n, j;
printf("Please enter value of n : ");
scanf("%d", &n);

[code]....

I know I'm not supposed to use system("PAUSE"), but this is self-study.

View 8 Replies View Related

C++ :: Program To Calculate BMI

Oct 7, 2013

I'm trying to successfully run a program that calculates your BMI but, although it runs, it is not giving the the correct math. Instead, it gives me the number i've submitted as my weight as an answer. I'm using Visual Studio 2008 and the formula: weight / (height/100)*2

Here is my code

#include <iostream>
#include <cmath>
using namespace std;
int main() {
int weight;
int height;
double BMI;

[Code] ....

View 2 Replies View Related

C++ :: Calculate Something More Than A Var Can Handle?

Jan 1, 2013

Let's say I want to calculate something like PI using some algorithm, but with the number of digits I want to.

View 1 Replies View Related

C/C++ :: Calculate Sum Of Every Digit

Nov 22, 2014

I want calculate sum of every digit in my zip code so I wrote implementation function like that but, it shows "0" as answers, then I realize it should be call first, I add correctionDigitOf() in to constructor "Zipcode::Zipcode" then My zipcode are all "0' after I do this .....

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <cmath>
using namespace std;
class Zipcode {

[Code] ....

View 1 Replies View Related

C/C++ :: Contributions Will Not Calculate

Aug 7, 2012

Contributions won't calculate ...

#include <stdio.h> 
#include <conio.h> 
int main()  { 
float tax;
 float salary;
 float taxable;
 float taxmo;
 float contributions;

[Code] .....

View 1 Replies View Related

C++ :: Calculate Area Of Circle Without Pi

Mar 22, 2013

I was given an assignment for class to calculate the area of a circle using only the radius as a user input and not using Pi in the code. I need to do this by calculating the areas of a series of rectangles under the curve and adding them together. Using nested loops to continuously reduce the size of these rectangles until the approximated area value is within a margin of error less than 0.1%.

Code:
#include<iostream>
#include<cmath>
using namespace std;
int main ()

[Code] .....

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved