C/C++ :: Do While Loop And Average Calculation

Dec 9, 2014

I need to create average calculating program using do while loop.

t = 1 - sin(x) when x > 0;
t = 1 + x when x = 0;
t = a + sin(x) when x < 0;
primary information:
x changes from 1 to -1 by step h = -0.5, a = -2

#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
int a = -2;

[Code] ....

How this program should look that's why this probably looks just like a mess.

View 2 Replies


ADVERTISEMENT

C++ :: Average Calculation Function Not Working As Expected To

Dec 16, 2013

[URL] ....

My calculation function will not work like i wanted it to. It gives me 0 or a crazy number.

this is the function here:
the entire code is on the link:

double calculations(data&avgs) //Calculates the students grade into a final grade
{
int avg1;
int avg2;
int avg3;
int lab1;

[Code] ....

View 12 Replies View Related

C/C++ :: How To Find Average With For Loop

Sep 14, 2014

What i need it to do is ask the user for a number of cases. The user will input numbers and the program should add the inputs until zero or a negative number is entered and then out put the average of those inputs. The amount of cases is pretty much how many times an average will be done. so if the amount of cases is 4. and the inputs are 1,3,(1+3/2)0 then it should output 2. and that would be ONE case, next inputs are 5,6,4,0(5+6+4/3) the output is 5 and that is case two. etc.

Here is my code:

#include <iostream>
using namespace std;
double avgVal(int, int);
int main() {
int amountOfCases;
cin >> amountOfCases;
int* numbers = new int[amountOfCases];
int input=0;

[Code] ....

View 2 Replies View Related

C :: Finding Largest / Smallest / Average In A Loop

Feb 9, 2013

I'm trying to write a program that will allow a user to enter infinite numbers (one at a time) with a way to stop entering values, and once it stops it immediately displays:

Lowest number:
Highest number:
Number of values entered:
Average of numbers:

what I can't figure out is:

-how to end the loop with something other than a number, preferably a char, so that it doesn't affect the average/lowest/highest

-how to output the lowest and highest numbers in a loop (would be easier to figure out were it finite and I could just type a bunch of printf/scanf)

What I have so far:

Code:

#include <stdio.h>#include <stdlib.h>
#define pause system("pause")
main(){
//n = amount of numbers input
//x = number given by user
//s = smallest number
//l = largest number
}

[code].....

View 4 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/C++ :: Compute Sum And Average Of All Positive Integers Using Loop

Oct 8, 2014

I got an assignment which asked me to create a program that asks user to input 10 numbers (positive and negative) integer. The program would be using loop to compute sum and average of all positive integers, the sum and average of negative numbers and the sum and average of all the number entered. But, the new problem is after I've entered all the number, the answer that the program gave me wasn't the answer that the program supposed to give. I don't know how to describe it, I would attach a picture and the code below:

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
//Declaration
int x, value, sum, average, SumPositive, SumNegative, Positive, Negative;
float AveragePositive, AverageNegative;

[Code] .....

View 12 Replies View Related

C/C++ :: Finding Average Time Complexity Of A Nested Loop?

Oct 29, 2014

We were discussing how to find average time complexity of different algorithms. Suppose I've a the following nested loop

for(int i=0;i<n;i++)
{
min = i;

[Code].....

Now the outer loop will iterate N times. the inner loop will always iterate 3 times no matter what the value of N is. so the worst case time complexity should be O(n^2) but what about the average case and the best case? I mean in terms of searching we can figure out and distinguish between the worst,best and average as it depends upon the number of comparisons. But here how can the average and best case be different then the worst case.

View 13 Replies View Related

C++ :: Finding Smallest / Largest And Average Number - Do While Loop

Sep 10, 2013

I am stuck looking at whats the problem ....

#include <iostream>
using namespace std;
int main() {
float average, largest = 0, smallest = 0;
int count = 1;
int num;

[Code] .....

View 1 Replies View Related

C++ :: Using A For Loop To Input And Output Array Values Also Calculate The Average

Jan 24, 2014

I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average

*/
#include <stdio.h>
int main(void)
{
/* Declare an array of integers */
int Grades[5];
int nCount;
int nTotal = 0; /* Declare and initialise the value */
float fAverage;

[Code]...

View 1 Replies View Related

C++ :: Calculate Average Of A Stream Of Positive Numbers - Loop Program?

Feb 25, 2013

Write a program that calculates the average of a stream of positive numbers. The user can enter as many positive numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, treat zero as a positive number, i.e., zero counts as a number that goes into the average. Of course, the negative number should not be part of the average. You must use a function to read in the numbers, keep track of the running sum and count, compute the average, and return the average to the main() function. Note that you must use a loop to do this, as you don't know how many numbers the user will enter ahead of time. I am having problem writing a loop program for it..

View 1 Replies View Related

C :: Print Correct Normalized Value / Average And Values Above Average

Nov 14, 2013

I must write a function that has a one dimensional double array and the number of values in the array as its arguments. Normalize the values. I must also print the maximum, minimum, average and numbers of values above the average in the array.

The equation that computes the normalized value from a value x is:

Normalized x= (x-min(array))/(max(array)-min(array))

My code does not print the correct normalized value, average and values above average.

Code:
#include <stdio.h>
int findMax( double array1[], int num_elements) // This function computes the maximum value of the array
{
int i, max=-32000;
for (i=0; i<num_elements; i++)

[Code] .....

View 5 Replies View Related

C++ :: Average Negative / Positive Numbers And Total Average?

Nov 18, 2013

I am trying to average the negative numbers and positive number and of course the total average.

This will read in a list of n values, where n is not known ahead of time. The number of values read into the array will be saved in n.

vector<int> readList() {
std::vector<int> result;
ifstream inFile;
inFile.open("setA.txt");
for (int x; inFile >> x; ) {
result.push_back(x);

[code]....

array is a one-dimensional array of integers and n is the number of elements in that array that contain valid data values. Both of these are input parameters to the function. The function must calculate 1) the average of the n integers in array, storing the result in ave; 2) the average of the positive numbers (> 0), storing the result in avePos, and 3) the average of the negative numbers (< 0), storing the result in aveNeg.

void avgs (std::vector &array, int &ave, int &avePos, int &aveNeg) {
int sum = 0, pos_sum = 0, neg_sum = 0, pos_count = 0, neg_count = 0;
for (auto i : array) {
sum += i;
if (i > 0) { pos_sum += i; ++pos_count; }

[code]....

View 1 Replies View Related

C++ :: CRC 32 Calculation Of File

Jan 3, 2014

i need to calculate crc32 of a input file and check with the original crc value of a file and return true/false,

View 4 Replies View Related

C++ :: Simple Calculation Going To 0 Every Time

Aug 8, 2013

I tried to write a simple program to calculate monthly yield, APR, and principle in various directions. Anyway, here's some code to get the APR from the principle and monthly yield. When I run it though, it spits 0 at me every time! What the problem is; the other functions work just fine and the code line for the APR calculation is just what it ought to be - I see neither a math nor tech problem here.

Here is the offending function:

Code:
void calculateAPR() {
int principle, monthlyYield, apr;
cout<<"
Please input the principle:";
cin>>principle;
cin.ignore();

[code]....

View 4 Replies View Related

C :: Calculation Of A Bitwise Expression

Mar 6, 2015

I would like to ask about how we calculates the following bitwise expression.

Code:

unsigned char ch[2] = {0x49,0x49};
ch[0] | ch[1] << 8; I'm thinking ch[1] << 8 as 0x00 ...

So, I think that the above expression converts to 0x49 | 0x00 ... and the complete expression should be 0x49 for me.

But, the compiler gives me the result of 0x4949 as two bytes.How does the compiler calculate this expression as two bytes?show me the steps included in the calculation of this expression?

View 2 Replies View Related

C :: 2 User Inputs For Calculation

Apr 9, 2014

I want to have calculations take place inside a switch statement that calls the appropriate function. The menu portion of the program works well, but I can't figure out how to let the user actually input 2 different numbers to the functions. My questions are:

1. If I use scanf to assign values to the variables, what determines end of input to each variable? (ie.. scanf("%d%d", &a, &b) what is the end of a, what is the end of b?)

2. Should I assign the variables to user input inside the switch, or try to do it in the functions below?

3. Is there something I haven't thought to ask that will screw me over? I'm really new to this.

Code:
#include<stdio.h>
int add(int b, int a);
int mult(int b, int a);
main() {

[Code] ....

This really was a test of multilayer menu, but I want to add functionality if I can.

Changed a variable before posting and didn't change all the conditions testing it.

View 3 Replies View Related

C++ :: Simple Calculation Of Char?

Dec 17, 2013

void viewWasteReport(){
EXEC SQL BEGIN DECLARE SECTION;
char wasteid[5],wastetype[31],month[11],wastequantity[13],wasteweight[11];
//double wastequantity[13];
//double wasteweight[11];
EXEC SQL END DECLARE SECTION;
fnConnectDB();

[Code] ....

I want to obtain the the product of wastequantity*wasteweight, but i get error.

View 6 Replies View Related

C++ :: How To Do CRC Calculation For Base64 String

Aug 1, 2013

I am trying to calculate a CRC of a Base64 string.I give you the correct checksum : 2942042514...And now the string :

AQAAAAAAAABsYAAAAAAAAENvbXByZXNzZWRUaXRsZQB4nO0d2XIaSbI+hZ13
m0NCR0QNE7KOHcXKlkMwtnhyIIRkdjGwgGxpP35386jqursRsk0zQygkd+dR
lVmVmZVdl//3Xyl+E4/iixiJivgqBmIm5mIoJmIsfhW/iLp4LWrwbwUwY9EH
[code]....

I tried CRC 16, 32 and with polynomial 0xEDB88320L, and with all these tries, I cannot find the correct checksum, it is my main problem.I don't want C++ code source, but I am searching for the method or algorithm to find it. If you want to know, this string in base64 contains an string compressed in zip, which contains an UTF16 XML. I want to modify information, and modify Adobe Projet (prproj)

View 6 Replies View Related

C++ :: Inflation Calculation For Two Years?

Oct 1, 2014

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

[Code]....

Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Ask the user to input the current price of an item and its price one year and two years ago.

To calculate the inflation rate for a year, Uh, no, that’s wrong! To calculate the inflation rate for a year, subtract the price of the item ONE YEAR AGO from the price of the item for that year and then divide the result by the price a year ago. For example: 2014-Inflation-Rate = (2014-Price minus 2013-Price) / 2013-Price.

Your program must contain at least the following functions:

•a function to get the input
•a function to calculate the results
•a function to output the results

View 1 Replies View Related

C/C++ :: How To Do CRC Calculation For Base64 String

Aug 1, 2013

I am trying to calculate a CRC of a Base64 string. I know the answer of the checksum, but I don't how to calculate it (It is for Adobe project).

I give you the correct checksum : 2942042514

And now the string :
AQAAAAAAAABsYAAAAAAAAENvbXByZXNzZWRUaXRsZQB4nO0d2XIaSbI+hZ13
m0NCR0QNE7KOHcXKlkMwtnhyIIRkdjGwgGxpP35386jqursRsk0zQygkd+dR
lVmVmZVdl//3Xyl+E4/iixiJivgqBmIm5mIoJmIsfhW/iLp4LWrwbwUwY9EH
+C1gx+KesH+IjjgTr4Bqj2h+Ey0hxRHQTMQNcHwSV/A0EYsA3oFSFlDngDAf

[Code] ....

I tried CRC 16, 32 and with polynomial 0xEDB88320L, and with all these tries, I cannot find the correct checksum, it is my main problem.

View 12 Replies View Related

C++ :: Possibility Of Compile Time Calculation

May 13, 2013

Is there any possible way of calculating some values at compile time? I have the following code of genereting upto 2000000010 palindrome numbers.

Code:
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdlib.h>

[Code] .....

As you see, I have taken input from the user just after calculating the whole palindromes. So cant we calculate this at compile time? because runtime of this program is extremely slow.

Another qs. I first tried to use array but It didnt allow 2*10^9 sized array. so what should I do whenever I need that size of array?

View 12 Replies View Related

C :: Simple Calculation - Function To Do Factorization

Feb 8, 2014

I wrote a function to do factorization (n!). while this function works perfectly:

Code:
int fact (double x){
register int z=1;
if (x==0)
return 1;
else
for(x;x;x--)
z*=x;
return z;
}

this doesn't:

Code:
int fact (double x){
if (x==0)
return 1;
else
for(x;x;x--)
x*=x;
return x;
}

what makes the second one different from the first one? can't see the difference..

View 1 Replies View Related

C :: Output Calculation (random Numbers)

Mar 24, 2014

Why do i keep getting wrong results

Code:
#include "stdafx.h"#include <stdio.h>
#include <string.h>
nt main(void){
char name[40];
int numbers[50];

[Code] .....

View 4 Replies View Related

C++ :: Calculator Program - How To Do Sine Calculation

Apr 26, 2013

I am basically trying to make a program for a calculator. I am struggling with how to do the sine calculation. this calculation will take place at line 158.

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

double firstNumber = 0.0;
double secondNumber = 0.0;
char operation =' ';

[Code] ....

View 1 Replies View Related

C++ :: Payroll Program - Calculation Error?

May 22, 2014

I'm working on a payroll program and I'm having problems that are causing calculation errors.

My input file is
1234FredJones4025.00
2345 TerrySmith6010.00

The errors I get are from the regular pay, over time pay, gross pay, tax amount and net pay calculations. They all look similar to this (6e+002). I believe they are occurring because regular pay isn't calculating correctly and the rest depend on that for their calculations. However, I can't see why regular pay isn't calculating correctly.

#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
class payroll{
ifstream fin;
char employeeid[100];

[Code] .....

View 14 Replies View Related

C++ :: Getting Strange Print Out For Calculation Of Volume

Apr 4, 2013

// DEBUG3-4
// This program contains a class for a cylinder
// Data members are radius and height
// The volume is calculated as pi times radius squared times height
// If no height is given, it's not a cylinder - it's a circle!

#include<iostream>
using namespace std;
//declaration section

[Code].....

View 1 Replies View Related







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