C :: Calculates Factorials Of User Input

Apr 12, 2013

This is a function that calculates factorials of the user input.I'm not getting a favorable printf result.

Code:

void calcFactorial ()
{
int arr [100];
int num = 0;
int i;
int factorials = 0;
int product = 1;
}

[code].....

View 2 Replies


ADVERTISEMENT

C++ :: User Input Number And Then Computer Calculates It For Fibonacci Series

Mar 15, 2013

I was asked to write a code that has the user input a number and then the computer calculates it for the Fibonacci series. The output should be separated by commas and a period should follow the last number. Ex. 1,2,3,4,5. <---period

I can't seem to get the period at the end. I have the commas and everything else. Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double num;

cout << "How many Fibonacci numbers do you want to display?";

[Code] ....

View 3 Replies View Related

C/C++ :: How To Get Large Factorials

Oct 7, 2014

How to get large fatorials in c++...in c++ i am getting the ouput upto maximum of 20!

View 4 Replies View Related

C :: Writing Factorials And Calling Other Functions To Do So

Jul 6, 2013

I am trying to get this statistical equation to work. m! / n! (m-n)!.

Code:
#include <stdio.h>
long factorial_M(long); // function prototype //
long factorial_N(long);
long total (long);
int main(int argc, const char * argv[]) {

[Code] .....

View 13 Replies View Related

C++ :: How Do Function Count Factorials - Recursion

Apr 3, 2013

How do function count factorials in this program?

#include<iostream>
#include<conio.h>
using namespace std;
void main(){
unsigned int factorial(unsigned int value);

[Code] .....

View 7 Replies View Related

Visual C++ :: Solving Factorials - Large Numbers?

Nov 21, 2013

If i m writing a code for a program to solve factorials, what is the best approach if i have large numbers in mind?

If i use int, i can only go upto 4bytes and if i use double i can go upto 8bytes. so should i create new type or is there any other way to get this done.

View 14 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 :: Program That Calculates Batting Average

Apr 21, 2014

I'm trying to put what i've learned into a little program that calculates batting average.

I want to store the batting averages of the players in an array and printf the best average at the end by name for example Dennis Ritchie had best batting average at .600.

I'm having trouble understanding how and what type of array to use.

Code:
int main(int argc, const char * argv[]) {
char playerName[20];
int totalPlayers, atBats, totalHits, x;
float battingAvg;

// Get total number of batters
printf("How many batters?

[Code] ....

View 2 Replies View Related

C :: Calculates Area Of A Triangle - If Statement

Jun 10, 2013

I am currently learning "if statements" while doing a program that calculates the area of a triangle. My problem is that the result is always "0". I am pretty sure the problem lies within my math, but how I have set it up wrong.

I am using Heron's Formula. Here it is for reference:

area=sqrt(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2

Code:
#include <stdio.h>
#include <math.h>
int main () {

float area, sideA, sideB, sideC, halfP;

[Code] ....

View 4 Replies View Related

C++ :: Program To Calculates Hypotenuse Of A Right Triangle

May 12, 2014

How to do the function part here is the question. "Write a program that calculates the hypotenuse of a right triangle. the program should ask the users to enter the length of the two legs of the right triangle and the program should call a function hypotenuse() that will calculate and display the length of of the hypotenuse. NOTE: The program should include a prototype for the function hypotenuse()" i have this so far

#include <iostream>
4 #include <cmath> // Needed to use the sqrt function
5 using namespace std;
6
7 int main()
8 {
9 double a, b, c;

[Code] ....

View 4 Replies View Related

C++ :: Create Function That Calculates Sum Between Two Containers

Jul 1, 2012

I need to create function Sum() that calculates sum between two containers. Code below work fine except function Sum between two containers...

How I should re - write my code that everything work fine.

Condition of exercise is : "Also create a Sum() function that calculates the sum between two iterators. The function then uses the template argument for the iterator type and accepts two iterators, the start- and end iterator"

1>------ Build started: Project: HP2_ex2_iter, Configuration: Debug Win32 ------
1> main.cpp
1>c:all myс++ha level 7solutionlevel 7 homework overview of the standard template libraryhp2_ex2_itermain.cpp(47): error C2275: 'C1' : illegal use of this type as an expression

[Code]...

View 5 Replies View Related

C :: Program That Calculates The Area And Circumference Of A Circle

Sep 27, 2014

I trying to write a program that calculates the area and circumference of a circle.

This is what I wrote so far.

Code:

#include <stdio.h>
void main()
{
int r;
int pi=3.14159265;
float cir,area;
printf("
enter the radius of the circle ");

[Code]...

the Problem is when I input the radius the answer I get is zero regardless of the the radius. Am I missing something?

View 4 Replies View Related

C++ :: Function That Calculates Euclidean Distance Between Two Points

Feb 24, 2015

I am trying to write a function that calculates the Euclidean distance between two points described by
π‘‘π‘–π‘ π‘‘π‘Žπ‘›π‘π‘’ = √(π‘₯1 βˆ’ π‘₯2)2 + (𝑦1 βˆ’ 𝑦2)2
Input Prompt
Enter x1, y1, and x2, y2:
Output Prompt
The distance is XXXX.XXX

Replace XXXX.XXX with the calculated distance precise to three decimal points.

Will this be a smilier input to the same forum that wasted posted a few years ago on this site?

Here is the link... [URL]..

View 2 Replies View Related

C++ :: Create A Program That Calculates Fraction Of Time?

Dec 16, 2013

I am trying to create a program that calculates fraction of time remaining when a student leaves during the middle of the semester. I have to use function files here. I am having trouble with the division in function long double tuitionfrac(int, int, int). No matter what numbers are entered, fractime gives an output of 0. I don't understand that.

long double tuitionfrac(int opening, int leaving, int semend)
{
int lefttime = semend - leaving;
cout << "Left time " << lefttime << endl; //for error checking
int tottime = semend - opening + 1;
cout << "Total time " << tottime << endl;
long double fractime = lefttime/tottime;
cout << "fractional time " << fractime << endl; //always returns as 0.
return fractime;
}

View 4 Replies View Related

C++ :: Finding Program That Calculates Student Grades?

Jun 7, 2013

I have to make a program that reads two student grades, the average of the two has to be 6, if you can not take an average of 6, will make a third test and calculate a new average.

I'm not getting the new display medium, without repeating the approved and disapproved?

// TRABAV2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {

[code]....

View 1 Replies View Related

C/C++ :: Using Program That Calculates Test Average Using While Loop?

Sep 23, 2014

I am working on a program that calculates the average of a list of test scores entered, with the list ended with a negative score (which is not calculated), as long as a user enters a name.

#include<iostream>
#include<string>
using namespace std;
int main() {
string name;
double score = 0.0; //user input score

[code]....

I have gotten the while loop to function. The problem lies in the calculation in the average of the test scores, such as when I enter the scores 87 76 90 -1 , which is supposed to give an average of 84.3 but my result when outputted is 86. what the problem is and what I can do to fix this error?

View 1 Replies View Related

C++ :: Switch Case - Program That Calculates Students Grade

Apr 18, 2013

Trying to write a program that calculates a students grade based on how many assignments have been graded. I am using a switch case since there is a total of 5 assignments, however when I enter case 1, and enter in how many I got out of 100, it just closes the program it doesn't go to the next part.

#include <iostream>
using namespace std;
char calculategrade(int total);
int main() {
// local variable declaration:
char input;

[Code]....

View 6 Replies View Related

C++ :: Define A New Member Method Which Calculates Value Of Term And Display It

Jul 30, 2012

A class called 'sample' with the data a, b and c and two methods as defined below. Define a new member method 'term()' which calculates the value of the term (2b - 4ac) and displays it.

Define the method outside of the class definition. Write the main method to create an array of 2 objects called D of class 'sample' and display the values and find the solution to the term (2b - 4ac)

My code so far:

#include <iostream>
using namespace std;
int term(int a, int b, int c) {
int result;
result = (2*b - 4*a*c);

[Code] ....

Problem: I keep getting error messages, here is a look at the ones i'm getting.

error: ISO C++ forbids declaration of 'cout' with no type.
error: expected ';' before '<<' token.
error: new types may not be defined in a return type
error: expected unqualified-id before '{' token.

View 5 Replies View Related

Visual C++ :: Program That Reads Numbers From A File And Calculates Average

Mar 13, 2014

[URL] .....

Here is my code and basically these are the steps. I feel like we have something good to work on but we keep getting errors.

a. Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.

b. Save the output of the program in a file.

c. Modify the function getNumber so that it reads a number from the input file (opened in the function main), outputs the number to the output file (opened in the function main), and sends
the number read to the function main. Print only 10 numbers per line.

d. Have the program find the sum and average of the numbers.

e. Modify the function printResult so that it outputs the final results to the output file (opened in the function main). Other than outputting the appropriate counts, this new definition of the function printResult should also output the sum and average of the numbers.

View 12 Replies View Related

C++ :: Second User Name Input Is Being Skipped

Jan 1, 2014

In this simple end-of-chapter problem, the ages of two people are to be compared and determine who's older. The problem I'm experiencing is that the second user name input is being skipped and going straight to the second users age.

So while running the program it looks something like:

What is user ones name?
<input name>
How old are they?
<input age>
What is user twos name?
How old are they?
<input age>
<if statement result>

Here's my code:

Code: #include <iostream>
#include <string>
using namespace std;
int user_one_age;
int user_two_age;
string user_one_name;
string user_two_name;

[code].....

View 9 Replies View Related

C# :: TexBox User Input To Hex Value

Sep 2, 2012

So I've got this form that a user puts in a numeric value into a text box. This value then has to be placed into a byte string of data so that it can be transmitted over as a packet. Bellow is what I have so far:

Code:
Byte[] OUTBuffer = new byte[65];//Allocate output memory buffer
Byte[] INBuffer = new byte[65]; //Allocate input memory buffer

if (setmSpeed == true)
{
OUTBuffer[0] = 0; //Not used, must be set to 0
OUTBuffer[1] = 0x85; //Command mode

[Code] ....

I've put in red the area where I'm having issues. I've tried different methods and have not been able to get this working yet. It only works if I speciffy the value manually as with OUTBuffer[1] = 0x85;, but I want byte 2 of OUTBuffer[] to be set with what I put in the text box.

View 4 Replies View Related

C :: User Input To File

Mar 18, 2013

I'm creating a program that should create a structure of a list of people entered by the user; the only problem I'm having is with the %c. When I have it, the loop only occurs once; if I put a %s, the loop occurs up to 25 times, but it doesn't write to the text file. Here is the code:

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
[code]....

View 2 Replies View Related

C :: User Input With Forks

Apr 7, 2013

So im working with forks and creating 2 fork processes. One child and parent. What im trying to get the child to ask me for a value. Then the parent would start to figure out the value and keep trying. Once it figures it out its tells them you got it and simply stops the program. I cant seem to get the program to keep guessing and stop when the number is found which sends a sigint. Here's what i have so far.

Code:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdbool.h>

int main() {
int j, i,pid;

[Code] .....

View 2 Replies View Related

C++ :: Alter User Input

Feb 6, 2013

I have this code here that counts the number of alphabetic letters the user's input,the number of characters total, the number of words and the number of "the" that was used. However now I need to alter the user's input to have two spaces after the end of each period, no spaces between a word or comma and each sentence has to have a capitalized letter and display them at the end. And I'm stuck on the altering part. I briefly started the 2 spaces after each period but it won't display anything.

#include <cstring>
#include <iostream>
using namespace std;
int main ()

[code]....

View 7 Replies View Related

C++ :: Trying To Get User Input Into Array

Apr 25, 2014

I have written a program and i had to pass an array into a function and now i have a variable for the subscript of the array and i was the user to input data, specificlly a string, more specifically first and last name without having to create two arrays, i have to do this with other things in the program as well, here is part of the program:

int addFunc(const int totNum, string city[],string state[],string street[],string name[],
int addNum[],int zip[],int telNum[],double bal[],int dateLp[], int addCount, int accNum, int usNum)//function will add a new account {
int countAf = 1;
if (usNum < 20)

[Code] ....

it should be able to take firstname space lastname

View 5 Replies View Related

C++ :: Divide User Input By 2 Until 1

Nov 10, 2014

I need to make a program that takes in a user’s number and keep dividing it by 2 until it is 1.I need to display the division steps ...

I do not know how to keep making it divide by 2 until 1. I tired this but it obviously did not work..

Code:
#include <iostream>
using namespace std;
int main() {
//User Input
int input,total;
cout <<"Enter A Number To Be Divided By 2 Until 1" << endl << endl;

[Code] ....

View 7 Replies View Related







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