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 () {
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 ()
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?
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;
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; }
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[]) {
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?
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;
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.
B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.
I got an assignment at school asking for a program that can implement functions that store, get and deletes text/binary data to a given memory area. We are supposed to make kind of like a tiny-mini OS..any links to some tutorials or explanations hon ow to understand this and be able to make a program like this on my own?
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
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?
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.
I'm supposed to print a small rectangle inside concentric circles that are inscribed in a rectangle.I'm not really sure where to start with printing a circle in a ppm file.
Found a good beginner's tutorial to learn Visual C++: [URL] ....
How to change the drawing so that instead of squares, the game draws circles. Can figure out that using Ellipse in the code results in circle outlines, but the fill remains as square color shapes.
The drawing code from the tutorial is below. How to substitute filled circles for filled squares.
Code:
// CSameGameView drawing void CSameGameView::OnDraw(CDC* pDC){ // First get a pointer to the document CSameGameDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(!pDoc)
#ifndef CIRCLE_H #define CIRCLE_H class Circle { public: //constructors Circle(); Circle(double r);
[code]....
The function isBigger() returns true (or false) if the radius of the Circle instance on which the function is invoked is bigger (or smaller) than the radius of the Circle instance passed to the function.: How to implement this function?
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?";