C++ :: Program To Calculate Average Of 3 Numbers - Undeclared Identifier

Sep 22, 2013

Write a program that will calculate average of 3 numbers

#include <iostream>
int
main(){
// prototypes:
float add_and_div(float, float,
float);

[Code] .....

i get the following errors:

error C2065: 'cout' : undeclared identifier
error C2065: 'cin' : undeclared identifier
error C2065: 'cout' : undeclared identifier
error C2065: 'endl' : undeclared identifier

View 2 Replies


ADVERTISEMENT

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++ :: Fin Undeclared Identifier But Is Declared

Apr 8, 2013

Program is not finished as I can't get passed read_data

Error:
"error C2065: 'fin' : undeclared identifier
error C2228: left of '.open' must have class/struct/union type is ''unknown-type''

#include "stdafx.h"
#include <iostream> // for streams
#include <iomanip> // for setw()
#include <fstream> // for files
#include <cstdlib> // for exit
using namespace std;
void read_data(int A[], int size)

[Code] .....

View 2 Replies View Related

C/C++ :: Use Of Undeclared Identifier (colours)

Oct 15, 2014

I keep getting this error message when i try to build the program.

#include <stdio.h>
#include <stdlib.h>
int main () {
int opt;
do {
printf("Please choose an option:
");
printf("1. Calculate resistance value

[code]....

The error messages that i am getting are :

error: expected expression (line20)
error: use of undeclared identifier 'colours' (line 47)

View 5 Replies View Related

C++ :: Function Prototypes - Undeclared Identifier

Feb 17, 2013

Why "Team" and "NUM_MEMBERS" are undeclared identifiers? I'm not sure I understand why it's giving me errors for those.

//Function Prototypes
void initialize (vector <Team> & tV, const int ID [],
const string m[][NUM_MEMBERS], int arraySize);
void printList (const vector <Team> & tV);
void menu ();
void add (vector <Team> &tV);
int search (const vector <Team> &tV, unsigned int size, int ID);

View 3 Replies View Related

C++ :: Value Assigned To Variables X And Y Via Cin - Undeclared Identifier

Aug 28, 2012

I've assigned value to variables x and y via cin, but when I try to compile it, I'm getting:

"1>c:users
isedocumentsvisual studio 2010projects ryityourself ryityourself ryityourself.cpp(26): error C2065: 'x' : undeclared identifier
1>c:users

[Code] .....

Code:
#include "stdafx.h"
#include <iostream>
void enterfirst() {
using namespace std;
int x;

[Code] .....

View 5 Replies View Related

C++ :: Binary Search Tree - Undeclared Identifier

Mar 8, 2013

I'm trying to create a template binary search tree and I'm getting all these vague errors that I have no clue how to solve. I've narrowed it down to my findMax and findMin functions but i can't figure it out any further than that.

template<class T>
class BinarySearchTree{
private:
struct BinaryNode{
T data;
BinaryNode *left;
BinaryNode *right;

[Code] .....

and here is are the errors I'm getting from this header file.

1>------ Build started: Project: Programming Assignment 2, Configuration: Debug Win32 ------
1> main.cpp
: error C2143: syntax error : missing ';' before '*'
: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
: error C2065: 'T' : undeclared identifier

[Code] ....

View 2 Replies View Related

C++ :: Error C2065 Balance - Undeclared Identifier

Feb 1, 2014

I receive this error, been couple hours try to understand, but i havent find the solution.

i get the error here:

case 2:

currentBalance(balance);
main ();

is it because it doesnt have a value, i serious dont know what my problem.

My whole code.

// Lucky ATM.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>

[code]....

View 13 Replies View Related

Visual C++ :: No Circular References But Undeclared Identifier

Jun 11, 2014

Each of my header includes is protected by directives. I think I don't have to include Boolean in my work space because it is already included in the external dependencies section. and the Boolean.h is in the include path.

MachineShop, Boolean etc got undeclared identifier error

Tried to comment out the directives, to no avail.

Code:
#include <iostream>
#include <string.h>
#ifndef BOOLEAN_H_
# include "Boolean.h"
#endif
#ifndef PROCESS_H_
# include "Process.h"
#endif
#ifndef MACHINESHOP_H_

[Code] ....

View 2 Replies View Related

Visual C++ :: New Linked List Error - Undeclared Identifier

May 30, 2013

I dynamically allocate a new list in the recMergeSort function which should run a constructor but when it get to the functions that use it, I get error C2065: 'otherHead' : undeclared identifier. I have tried setting it to NULL and it didn't work. I even copied the default constructor to a set function and I still get the errors.

Code:
template<class Type>
void unorderedLinkedList<Type>::recMergeSort(nodeType<Type>* &head) {
otherHead = new nodeType<Type>;
if (head !=NULL)
if (head->link != NULL)

[Code] ....

wonder if I'm sending the correct data type. Here is the heading of the functions that I'm using from the book.

Code:
void unorderedLinkedList<Type>::divideList(nodeType<Type>* first1,
nodeType<Type>* first2)

View 6 Replies View Related

C/C++ :: Calculate Sum And Average Of A Sequence Of Numbers

Feb 17, 2014

Write a C program that calculates the sum and average of a sequence of numbers. Assume the first number specifies the number of values remaining to be entered. If the first number is less than 1, then the program should display an "Invalid Entry ... Please enter a positive number." message.

THIS IS HOW IT SHOULD COME OUT...
Enter the number of values to process 0

Invalid Entry ... Please enter a positive number.

Enter the number of values to process 3
Enter 3 numbers:
1
2
3

Sum: 6
Avg: 2

THIS IS THE CODE I HAVE SO FAR...

#include <stdio.h>
int main(void) {
int total=0;
int howmany;
int i;
int value;

[Code] ....

View 8 Replies View Related

C++ :: Calculate Average From File Containing Array Of Numbers?

Feb 21, 2014

I have written two separate programs; Program 1 calculates the average of an array of numbers which has been hard-coded into the program. Program 2 reads an array of numbers from a text file and displays them on the output.

I wish to combine these two programs into one by making Program 1 read the array of numbers from the file and then calculate the average using that instead of the array { 84, 92, 76, 81, 56 } as outlined below. I only wish to display the average in the output, not the number array as Program 2 does.

I have tried to do most of the work, I just need modifying the code slightly so it reads the number array from the file and calculates the average.

Program 1

#include <iostream>
#include <cmath>
#include <math.h>
#include <fstream>
#include <string>
#include <numeric>
using namespace std;
int main() {
const int nNumStudents = 5;

[Code] .....

View 7 Replies View Related

C++ :: Test Scores Program With Pointers - Calculate Average?

Apr 7, 2013

I have created a program that allows for a user-defined number of test scores as input. After the user enters these scores, the program calculates the average test score. Here is my code:

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

[Code] .....

I am having trouble with the final part of my program. How do I pass the array of test scores to a function that calculates how many people got an A (90+) on the test? The final output should look like this:

The average of those scores is:
The number of A grades is:

View 2 Replies View Related

C :: Flowchart - Program To Compute Average Of N Numbers

Feb 20, 2015

How can you draw a flow chart that will be used to write a program to compute Average of n numbers?

View 1 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++ :: 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 :: Program To Calculate Factorial Of Numbers - For Loop

Feb 5, 2013

I have been working on a program to calculate the factorial of numbers. Part of my code is copied and modified from the FAQ about validating numbers in user input.

I have encountered a problem with the for loop that I am using near the end of my code. No matter what I do, it seems that my loop only does the multiplication of b = a*(a-1) and then prints. For example, inputting 5 will result in a print of 20, but the factorial is 120.

Code:
int main(void) {
char buf[BUFSIZ];
char *p;
long int a;
long int b;
long int i;

printf ("Enter a number to be factorialized: ");

[Code] ....

View 5 Replies View Related

C :: Rounding Of Numbers Using Int Identifier

Apr 23, 2013

I have an assignment for uni which requires the program to ask the user to input a number in for a variable to use in later equations. The assignment specifies that if the number that is input into the program is not an interger that it needs to be rounded UP to the nearest interger. e.g. 2.5 = 3, 5.00001 = 6 etc. i have identified this variable using "int" which i know makes it an interger however it also always rounds the number DOWN to the nearest interger. I was just wondering what the best way to approach this problem was. The only idea i have is to put + 0.99999 at the end of this variable when it is worked out so that if it is not a whole number it will be raised above the next interger and then rounded down however this will not work if there is too many decimal places.

View 6 Replies View Related

C++ :: Create A Program That Reads Numbers And Calculate Them On A Separated Subroutine

Nov 15, 2013

I need to create a program that reads some numbers, and calculate them on a separated subroutine, and the return of this subroutine must be the sum of all the numbers. I'm getting an error but I can't figure out why =/

#include <iostream>
using namespace std;
int calc(int val, int qtd){
int sum=0;
for (int cont=0; cont<qtd; cont++)
sum=sum+val;
return sum;

[Code]...

The error that I'm getting is on the line 22.

The error message: "invalid conversion from 'int*' to 'int' [fpermissive]

View 4 Replies View Related

C++ :: Calculate Average From Array Values

Jan 8, 2014

i wrote following code to calculate average of the values entered to the array.After displaying the output following error was displayed.

"Run-Time Check Failure #2 - Stack around the variable 'marks' was corrupted.

A buffer overrun has occurred in q 3 410005111.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program. "

//Average mark of student 1
cout<<"Avarage mark of the student 1 :"<<(marks[0][0]+marks[1][0]+marks[2][0]+marks[3][0]);
cout<<endl;

View 5 Replies View Related

C :: How To Calculate Largest / Smallest / Average - No Array

Feb 16, 2015

i'm having trouble trying to make this code works .. the program must repeatedly asks user for the age of a person until user enters -1 ,, once he/she entered -1 the program calculates ( smallest value entered, largest value , and average )excluding -1 from calculation

i've been working on this for a weeks this is the best i could do.i know average must add all the entered values , not only smallest and largest but how can i do that here ?

Code:

#include<stdio.h>
int main(void)
{
int age ;
int v;
int counter;
int l=0;
int s=0;
int limit;
}

[code]....

View 13 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

C++ :: Calculate Average Of Array And Print Elements

Oct 23, 2013

Use function decomposition.

-To prompt user to enter value and assign it to correct position in array
-calculate the average of an array
-display all element.
-display average.

For some reason, i keep getting error and it doesn't compile. I use Dev-C++

Here is my code:

#include <iostream>
#include <iosmanip>
#include <math.h>
using namespace std;
const int SIZE = 5;
const int LINE = 4;
//function prototypes
void getData(int arr[]);

[Code]...

My error is on line 69. I don't see anything wrong with it.

If i take out setw(3), it doesnt get any error but for some reason it doesnt run. Possible i did something wrong there?

View 2 Replies View Related

Visual C++ :: How To Calculate Average And Standard Deviation

Oct 21, 2013

I've been trying to calculate the Second standard deviation but the average in the second loop isn't calculating correctly which is causing the standard deviation (method 2) to not calculate correctly.

Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;
int main () {
cout << "
This program will produce statistics (Mean, Standard Deviation, "

[code]...

View 4 Replies View Related

C++ :: Dynamic Arrays - Sort Input Data And Calculate Average

Jul 15, 2014

I'm still fairly new to c++ and am having trouble with dynamic arrays. My task is to create an array for test scores. The user needs to define the size of the array and then input data to later sort and calculate the average.

Below is what I have so far. I am struggling with the user input part. I receive the following errors for the data input of the individual scores:

"error C2108:subscript is not of integral type"
"IntelliSense:expression must have integral or unscoped enum type"

Code :

#include<iostream>
#include<iomanip>
using namespace std;
int main() {
//user input total number of scores
cout<<"Please enter the total number of test scores."<<endl<<endl;

[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







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