C++ :: How To Write A Program To Calculate Pi To N Number Of Places

Aug 13, 2014

I assume floating point numbers in C++ have a default maximum of 5 decimal places. You can use setprecision() but is this limitless?

So how would find say write a program to calculate Pi to N number of places?

View 3 Replies


ADVERTISEMENT

C :: Write A Code To Calculate Minimum Number

May 24, 2014

I'm trying to write a code to calculate the minimum number of coins needed to cover a change. It works fine but i want to display a message telling the user to try again if they type something that's not a number or a negative number. But it's not working. When i type a negative number, the program runs normally and displays a negative value of coins instead of showing the message. And when i type something that's not a number, the program just keeps showing a lot of zeros nonstop. And when i try to compile it with 'unsigned float' instead of just 'float' i get errors.

Code:

#include <stdio.h>
int main()
{
unsigned int coins;
float change;
unsigned int n25, n10, n5, n1;
unsigned int r25, r10, r5;
}

[code]....

View 7 Replies View Related

C :: How To Write A Program That Will Calculate Stress

Feb 7, 2013

I recently signed up for ES201 class and am confused with how to compile a program in the C language that will convert ACT scores to SAT scores.

View 5 Replies View Related

C++ :: Write A Program That Uses Arrays To Calculate Sum And Display It

Nov 4, 2013

SO Im supposed to write a program that uses arrays to calculate the sum and display it. I keep getting the error that says the sum has to be initialized.

#include <iostream>
using namespace std;
//Function prototype
int sumArray(int);
const int NUM_ELEMENTS = 5;

[Code] .....

View 1 Replies View Related

C/C++ :: Write Program That Calculate Students CGPA And Store In To File Name

Jan 16, 2015

#include<fstream>
#include<iostream>
#include<string>

[Code]...

View 2 Replies View Related

C :: User Defined Number Of Decimal Places?

Sep 2, 2013

I need the user to be able to input the number of decimal places they wish to have displayed in the output. Everything works fine as is, I just don't know how to allow for the user to input the number of decimal places they want the output to have.

Code:

#include<stdio.h>
#include<math.h>
#define PI 3.141592654
int main(void) {
//Local Declarations
int x; //desired number of decimal places
float radius; //radius of circle
float circumference; //circumference of circle

[Code] .....

View 2 Replies View Related

C++ :: Program To Calculate A Grade Letter Into Number?

Feb 7, 2013

So I have to write a program to calculate a grade letter into a number.

Letter grades are A, B, C, D, and F, possibly followed by + or –. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F–. A + increases the numeric value by 0.3, a – decreases it by 0.3. If the letter grade is illegal (such as "Z"), then your output should be "INVALID LETTER GRADE"; If the combination is illegal (such as "A+" or "F-") then your output should be "INVALID GRADE COMBINATION"

Also the code should look like this
Enter your letter grade: C+
Grade value is [2.3]

// Input
cout << "Enter your letter grade: ";
string s;
cin >> s;

[Code].....

View 2 Replies View Related

C :: Program To Calculate Students Grades From Input File And Write To Output File

Aug 29, 2014

One of my class assignments is to create a program that receive a .txt file containing a students name and their grades as follows:

John K. 99, 87, 57, 89, 90, 95
Amanda B. Jones 100, 88, 76, 99, 86, 92
etc..

The number of students is unknown until run time. You have to take those grades and average them weighing the first (4) at 10% a piece and the last (2) at 30% each.

Then return an output file with the students name and their letter grade A,B,C,D,F based on their computed score. In addition, on screen it needs to display the average scores for each Q1, Q2, etc. as well as the minimum and maximum for each test on the screen. I am having a hard time in assigning the scores to a variable so that they can then be computed as an average and then used to determine a letter grade. I have begun to write the code and am a bit stuck..here's what I have so far:

Code:

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

[Code]....

View 2 Replies View Related

C++ :: How To Write A Program That Count Number Of Notes

Sep 17, 2014

How we will write a program that will count a number of notes. I mean if i have 5676 rupees and i want to find the number of 5 thousand pak currency ,the number of 1000 notes, the number of 500 notes and the number of 100 notes. How we design such a program of if rlse structure to perform the above task.

View 1 Replies View Related

C++ :: Write Program That Outputs The Number Of Characters?

Jun 3, 2013

I need to write a program that outputs the number of characters, words, and lines in the files that are supplied as command-line arguments.

#include <iostream>
#include <string>
#include <iomanip>

[Code]....

View 2 Replies View Related

C :: Calculate Number Of Bits In Type - Incorrect Result In Program

Feb 15, 2014

I have this simple program below:

Code:
#include <stdio.h>
#include <limits.h>
unsigned int rightrot(unsigned int x, unsigned int n) {

/* calculate number of bits in type */

size_t s = sizeof(x) * CHAR_BIT;

[Code] ....

The result it prints is 2684356604 on my 32-bit computer. The result I expect is as follows:
0xFF94 is 0000000000000000 1111111110010100 in binary.

Shift it right by 5:
0000000000000000 0000011111111100

Then take that result in shift it right by 27 (s is 32 and p is 5, so the difference is 27):
1111111110000000 0000000000000000

Now we use bitwise or:
0000000000000000 0000011111111100 | 1111111110000000 0000000000000000 = 1111111110000000 0000011111111100

That in decimal is 4286580732. So how does it come up with 2684356604?

View 2 Replies View Related

C++ :: Calculate Number Of Days Between Dates - Program Continuously Runs

Mar 24, 2014

I have an assignment to write a program that will calculate the number of days between two dates (including leap years). We have to read the data from a file and in my current input file I have:

1 1 2000 1 5 2004
5 2 2005 2 5 2009
1 15 1998 1 15 2001

for testing purposes. When I run the program the console runs continuously spouting out "The days between your two dates are 1097." Which would be the correct output for the last set of dates entered, but I need to find out where I've messed up in my main.

#include <iostream>
#include <fstream>
using namespace std;
bool isLeap(int x) {
if (x % 400 == 0) {

[Code] .....

View 7 Replies View Related

C :: Inventory Program - Entering Amounts With Two Decimal Places

Jun 7, 2013

So my inventory program runs fine as far as I can tell. Except when entering "Amounts" with more that 1-precision . ie

Amount Entered : 25.99 // Problem
Amount Entered : 25.9 // No Problem

When entering say 25.99, the rest of the file is jibberish. but 25.9, the rest of the file is fine

Code:
#include <stdio.h>
typedef struct toolRecord{
int record_num;
char tool_name[16];
int quantity;
double price;

[Code] .....

View 5 Replies View Related

C :: Program To Generate A List Of Powers Of 3 - Decimal Places?

Sep 23, 2014

So my assignment requires us to write a C program to generate a list of powers of 3 where each output line lists three numbers: k 3k 3‐k

It should look like this (just pretend all the numbers are lined up in their respective columns)

1 0 1.0
3 1 0.333333343
9 2 0.111111112
27 3 0.037037037
81 4 0.012345679
243 5 0.004115226
729 6 0.001371742
2187 7 0.000457247
6561 8 0.000152416
19683 9 0.000050805

This is what I keep getting:

1 0 1.000000000
3 1 0.333333343
9 2 0.111111112
27 3 0.037037037
81 4 0.012345679
243 5 0.004115226
729 6 0.001371742
2187 7 0.000457247
6561 8 0.000152416
19683 9 0.000050805

My input:

Code:
#include <stdio.h>
#include <stdlib.h>
void powers(void) {
int i=0;
int n=9;
int x=1;
float h=1;

[Code] .....

Notice how I'm getting 1.000000000 for my first h value in my output whereas I should be getting 1.0. What am I doing wrong?

View 6 Replies View Related

C++ :: Dice (with Varying Number Of Sides) Program To Calculate Percentage Of Results

Oct 28, 2013

I am trying to code and compile a program that requests a uses to first inpu the number of sides they wish for a dice to have and secondly input the number of dice throws they would like to calculate the value for. The program will print an error message and default the number of sides the dice has to 5 if the number entered is below 4. Finally it will print out a percentage figure for each value that results from all the the dice rolls.

I have attached my header, driver and class files below along with accompanying error messages below them

// file name Exercise.cpp
#include <iostream>
#include "Die.h"
using namespace std;
int main() // the main program begins here
{
char restart = 'y'; // declare variables
double numRolls = 0.0;
int diceTot = 0;

[Code] .....

View 5 Replies View Related

C++ :: Write Program Which Tells User If Number They Input Is Prime Or Not?

May 2, 2014

So I need to write a program which tells the user if the number they input is prime or not. I have done so and included the code below. My problem is that I need to allow the user to input if they want to enter another number after the first one using y or n and I am having trouble figure it out.

#include <cstdlib>
#include <iostream>
using namespace std;

[Code].....

View 5 Replies View Related

C++ :: Write Program That Prompts User To Enter Item Number

Jun 27, 2013

Write a program that prompts the user to enter an item#, the program should determine if the item is in the file and print the price of the corresponding item. If the item is not in the file an error message should be printed.

All I have so far is

string item_no=0;
cout<<"Enter a item#";
getline(cin,item_no);
if stream openData;

I need to finish the rest in pseudo code

View 2 Replies View Related

C :: Write A Program That Converts Alphanumeric Phone Number Into Numeric Form

Mar 6, 2015

i m learning c programming and i m stuck with this program for some reason.Write a program that converts alphanumeric phone number into numeric form:

O/P:
Enter phone number: CALLAT 2255288
here is the code i have written:
/** compilers shows no error **/
and O/P I get is
Enter phone number: CALLAT
/**blank space***/

Code:

#include<stdio.h>
int main(void)
{
char ch;
printf("Enter phone number:");
ch=getchar();
}

[code]....

View 4 Replies View Related

C++ :: Variable Initiation - Calculate Number Of Multiplications It Took To Reach A Certain Number

Feb 19, 2014

So I have a template, part of a larger code, that is designed to calculate the number of multiplications it took to reach a certain number. The problem is, whenever I execute the program, mults is always printing out a strange number, perhaps its actual address.

template <class T>
T power3(T x, unsigned int n, unsigned int& mults) {
if (n == 0) return 1;
if (n == 1) return x;
if (n == 2){

[Code] ....

View 10 Replies View Related

C++ :: How To Calculate Number Of Scores Above 90

Apr 7, 2013

I have a program that allows the user to enter a specific number of test scores. Based on these test scores, the program should display the average score and calculate how many of the scores were above 90. I have most of it done but I'm having trouble figuring out how to calculate the number of scores that were above 90. What am I doing wrong?

This is my code:

#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
double average(double*, int);
int howManyA(double*, int);

[Code]...

View 1 Replies View Related

C :: Calculate Prime Number Using Loops

Oct 10, 2013

how would I write a while() loop that calculates the sum of all prime numbers from 1 - 50.

View 5 Replies View Related

C++ :: How To Calculate Number Of Arguments In A Function

Aug 19, 2013

i'm trying building my how Write() function:

template <typename T>
....
Write(T Argument1[,T ArgumentX])

how can i calculate the numeber of Arguments added? (in C we used an argument for tells how many we putted in a function, but not in these case)

View 2 Replies View Related

C++ :: Calculate The Nth Number In Fibonacci Sequence

Feb 28, 2013

I was trying to create a code to calculate the nth number in a Fibonacci sequence, when the nth number is entered interactively.

View 4 Replies View Related

C/C++ :: Rotate Array By 2 Places?

Jul 25, 2012

input: array[] = {0,1,2,3,4};
output should be {3,4,0,1,2};

View 1 Replies View Related

C :: How To Calculate Number Of Digits After Decimal Point

May 24, 2014

How to return the value after the decimal point. For example:if two integer numbers are 3, 4 then (3+4)/2 is 3.5 the 5 after the decimal point is to be returned. if suppose it is 34.456 i have to return 456.

View 11 Replies View Related

C++ :: Random Number Generator And Calculate Average

Oct 15, 2014

I need to create a program that has has an array size of 20 and will generate 20 random numbers in it between 1-1000. Then I need to calculate the average of all the random numbers.

I have half of the code done ,but im lost on how to calculate the average of the random numbers.

Here what I have:

#include <iostream>
using namespace std;
int i;
int size[20];
int counter = 0;
int main() {
cout << "The Array Consists Of 20 Random Numbers: "<<endl<<endl;

[Code] ....

View 2 Replies View Related







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