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


ADVERTISEMENT

C/C++ :: Calculating Hypotenuse Of A Triangle

Apr 3, 2014

I wrote a function to calculate the hypotenuse of a triangle. My code looks fine but when i enter the two sides it does not give out the right answer. I really don't know what to do.

#include <stdio.h>
#include<Windows.h>
#include<math.h>
double hypotenuse(double side1, double side2);
int main(void){
double side1, side2, hyp;

[Code] .....

View 8 Replies View Related

C :: Calculate Hypotenuse Of Right Angled Triangle - Function Does Not Take 0 Arguments

Mar 9, 2013

error C2660: 'CalculateHypotenuse' : function does not take 0 arguments

Code:
#include"header.h"
#include<stdio.h>
#include<conio.h>
#include<math.h>

[Code] .....

View 6 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 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 :: 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++ :: 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

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++ :: Right Triangle Program Using X And Y

Jan 12, 2015

I originally had the user input three different lengths and then used this to determine whether or not it was a right triangle.

if(c==sqrt(a*a+b*b)||a==sqrt(b*b+c*c)||b=sqrt(a*a+b*b))

Now it has to be modified in order to accept the input 2,2 4,4 and 6,8(only an example) and be able to find out if it is a right triangle. I was told that arrays were not necessarily the only way to go about it.

View 1 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols

Jan 1, 2015

I'm making a program that prints a triangle of @ signs given rows (but not columns).

For example, the output with rows = 4 would be:
@@@@
@@@
@@
@

and rows = 3 would be:
@@@
@@
@

However, trying to make this has given me a program that does something similar (but not the same):

for example, with my current program rows = 4 outputs:
@@@@
@@@
@@
@

and rows = 3 gives
@@@
@@
@

It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:

1. The space needs to not apply to the first line.
2. I can't get it to make a space before each row without making a space between each column.

My current code is:

#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
int rows;

[Code] ....

I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?

View 4 Replies View Related

C++ :: Program That Prints Out Pascal Triangle?

Jan 20, 2015

I have a program that prints out pascal's triangle. One problem: it isn't a triangle. The output doesn't work. This is what it should print:

Code: How many rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 and this is what it does print: Code: Enter a number of rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

[Code]....

View 3 Replies View Related

C++ :: Program To Find Area Of Triangle?

May 26, 2013

i have written a program to find area of triangle, but i meet some errors,

//******area of triangle******//
#include<iostream>
using namespace std;

[Code].....

View 1 Replies View Related

C++ :: Hypotenuse For ONE Side And ONE Angle?

Dec 7, 2014

On a right angled triangle, if the user inputs only ONE side length (not the hypotenuse) and only ONE angle, what code is required to work out the hypotenuse? I know how to work out the final side and the remaining angle once I have this.

View 4 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols In A Certain Direction

Jan 12, 2015

So I need to make a program that prints a triangle of symbols in a certain direction.

For example: Code: How many rows? 3

@
@@@
@@@@@

How to do that. It's rare that I post without figuring anything out, but I'm just simply not sure. I have a program that prints a triangle in a similar direction, so maybe if I could get some hints as to what to do with that (HINTS, not direct source code) .

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

[Code] .....

View 6 Replies View Related

C :: Program That Returns Pascal Triangle Of N Rows

Nov 25, 2013

I need to make a program that returns pascal's triangle of N rows. I actually need to make a function of format "int **func(int n)". I don't know how to go about that, so I am trying this method first, but I seem to be getting an endless loop.

Code:
#include <stdlib.h>#include <stdio.h>
int *rowN(int rowNum, int* prevRow) {
int *rowN;
rowN=realloc(rowN,(rowNum+1)*sizeof(int));

[Code] ....

View 7 Replies View Related

C/C++ :: Right Triangle Program - Computing Lengths Of Sides

May 5, 2014

I made a simple program to compute the lengths of a triangles sides, but when I enter 30 for angle and 10 for hypotenuse I get the opposite side is -9.880316 and the adjacent is 1.542514.

#include <stdio.h>
#include <math.h>
main() {
float angle;
float hypotenuse;
float adjacent;
float opposite;

[Code] ....

View 2 Replies View Related

C :: Print All Pythagorean Triples With Length Of Hypotenuse

Oct 2, 2014

So this is a programming assignment right now that I'm working on. I was able to satisfy two or the requirements: to print all Pythagorean triples with the length of the hypotenuse being below the entered value and to state how many Pythagorean triples there are. I've come into a problem, though, since the final requirement is to state the largest Pythagorean triple. The problem is that it posts the values of a,b,c after the loop exits, which are going to be the values right below N (eg. N=19, then a,b,c=16,17,18).

Here is the program:

Code:
#include <stdio.h>
void main () {
int a,b,c,N;
int ctr = 0;

[Code] ....

My questions is how to fix this problem because putting it in the for loop will just cause it to repeat all values.

View 4 Replies View Related

C++ :: Program That Will Represent Axis-aligned Right Triangle In X-y Plane As A Class

Apr 10, 2013

I am having trouble of exactly how "class" works. I dont know what the difference between set and get is. I have this code:

#include <iostream>
#include <cmath>
using namespace std;
class Point {
private:
double px;
double py;

[Code] .....

How to get void Triangle::setBottomLeftX(const double x) to work.

Implement the get and set member functions for the class Triangle. Use the appropriate class attributes of the class Triangle.

a. The location of the bottom left vertex is stored in the member attribute blPoint.
b. The top left vertex can be computed from blPoint and the height.
c. The bottom right vertex can be computed from blPoint and the length.

View 19 Replies View Related

C :: Create A Program That Asks User To Input Integer Lengths Of Three Sides Of A Triangle

Sep 6, 2013

C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
int SideA;
int SideB;
int SideC;
}

[code]....

View 14 Replies View Related

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 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++ :: 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++ :: 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







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