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
ADVERTISEMENT
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
Feb 17, 2013
I want to have input data stored in a database. All information entered is to be stored under a single block. That way whenever I want to recover that information all I have to do is point to that block. Think of it like this. I want a large square block that can hold certain information. Inside of that large block are a finite amount of smaller blocks in which the user entered information about a single subject. Lets say block 1 has a name, address, and phone number. The second block will have the same TYPE of information, but different values as entered by the user. I.E:
BLOCK 1: Name 1, Address 1, Phone 1
BLOCK 2: Name 2, Address 2, Phone 2
etc.
The large block contains all of the smaller blocks, we will name the large block "Address Book" ... How would I implement that? Of course it would be just a simple console program that would erase all information when the program shut down, but I've been trying to figure out how to do it, but just can't seem to grasp a good notion of how to do it. What would be the best way to do that? Structures? How would I make it dynamic so that I wouldn't have to define every block, so that it would be added on the fly when someone inputs new information.
View 2 Replies
View Related
Sep 15, 2014
I am trying to code a program that takes in user inputted data about percentages and using it to later on calculate a final grade. 4 percents are inputted, for Assignments, Midterm1, Midterm2, and Finals. If the percents dont add up to 1 (i tell the user to enter the decimal value) I set up and if statement to catch it and end the program. Except that if i type in
Assignments = .3
Midterm1 = .3
Midterm2 = .3
Finals = .1
the program doesn't recognize that they add up to 1. Heres the relevant portion of my code [URL] ....
Here's some examples of how it works [URL] ....
And heres what i dont understand [URL] ....
Why is it saying .3 + .3 + .3 + .1 != 1 when .1 + .3 + .3 + .3 == 1?
View 1 Replies
View Related
Nov 5, 2013
Read the input file of data ( employees.txt) and store them in arrays. This company can have up to 55 employees [b]i need to do these following in these program:
Write a function to read the input file and store the data in arrays.
Write a function to calculate regular pay.
Write a function to calculate overtime pay
Write a function to calculate gross pay.
Write a function to bubble sort the employees into order by last name, first name.
Write any swap functions that are needed.
Write a function to write output to a file called payroll.txt
Format of file is EMPLOYEES.TXT[/b]
Hours Pay Rate Employee Number First Name Last name
40.0 10.00 A1234 Jane Adams
50.0 10.00 L8765 Mary Lincoln
25.5 10.85 W7654 Martha Washington
52.0 15.75 A9876 John Adams
45.0 25.00 W1235 George Washington
40.25 55.00 L9087 Abraham Lincoln
30.0 9.75 T9876 William Tell
42.5 12.50 M7654 Missy Muffett
30.0 10.00 P8765 Peter Piper
HERE IS MY CODE SO FAR:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void tellUser();
[code]....
View 9 Replies
View Related
Jan 4, 2013
I'm writing a program in which I have to use a matrix to represent a file in code. because it's a file, the size of the matrix is undefined, and therefore the matrix has to be dynamic. I found out that my compiler doesn't like dynamic multidimensional arrays, so I was thinking of this matrix as a dynamic (monodimensional) array of other dynamic (monodimensional) arrays. My program (and thus this example) uses unsigned chars.
unsigned char variable=something;
unsigned char**matrix=new unsigned char*[lenghtOfMainArray];
for(int rowNumber=0;rowNumber<lenghtOfArray;rowNumber++)
{
[Code].....
View 2 Replies
View Related
Dec 17, 2013
I have a question. How to find the average value of all the elements in a deque?
View 2 Replies
View Related
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
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
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
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
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
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
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
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
View Related
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
Apr 11, 2013
it compiles and runs, it gives me the average and the highest score but says lowest is 0 even though 0 is never entered.
Write a program which uses an array of 5 scores and calculates the average score, the highest score and the lowest score.
#include <iostream>
using namespace std;
int getHighest(int [], int);
int getSmallest(int [], int);
double getAverage(int [], int);
int count;
int numbers;
[Code] ......
View 2 Replies
View Related
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
Apr 12, 2013
I need to calculate the average and median of an array. I do not know how to put it in code.
View 1 Replies
View Related
Apr 11, 2014
I'm writing a program that will implement BubbleSort and MergeSort and time them as they sort a dynamic array with N elements. These are the instructions on what my main.cpp file should do.
main.cpp
Include all needed libraries for timing and random number generation while the number of element, N, is less than 100001 repeat the following.
create an array with N (initially 10) random elements
sort the same array with Bubble and Merge sort
time how long it takes each algorithm in microseconds (see example below)
Increase N by a factor of 10 (N *= 10)
Hint: you may want to put your merge sort object on the heap and delete it with every iteration of this loop
And this is what I have so far for my main.cpp
#include <iostream>
#include <sys/time.h>
#include <ctime>
#include <cstdlib>
#include <stack>
#include <iomanip>
#include "BubbleSort.h"
//#include "MergeSort.h"
[Code] .....
One of the errors that I'm running into is that I'm not sure how to correctly call the function I think?
View 3 Replies
View Related
Sep 15, 2014
how to put comparision condition in order to caculate total number of comparision in selection sort
static void selectsort(int[] data, int n)
{
int i, j;
for (i = 0; i < n; i++)
[Code]....
View 1 Replies
View Related
Feb 11, 2013
I am having troubles with dynamic arrays and pointers. All the errors are of that kind. I think when I am assigning malloc to an array we assign to its address.
Code:
/*Create an array of genes of the large matrix*/
gene_t gene,gene1,gene2;
gene=malloc(INITIAL*sizeof(gene2)); Code:
while(...) {
if (gene_num==current_size){
[Code] .....
View 9 Replies
View Related
Oct 1, 2014
Code to allocate the memory for my arrays in the create array function.
#include <iostream>
#include <cstdlib>
using namespace std;
typedef int* IntPtr;
const int NUMLABS = 4;
[Code] ....
View 1 Replies
View Related
Mar 28, 2014
By using operator overloads i need to be able to * two dynamic arrays;
this is what i have so far
MyInt operator* (const MyInt& x, const MyInt& y) {
MyInt Temp;
int carry = 0;
if(x.currentSize > y.currentSize){
for( int i =0; i < y.currentSize; i++)
for(int j = 0; j < x.currentSize; j++)
[Code] ....
View 7 Replies
View Related
Mar 4, 2014
i was trying to make a dynamic array in this form :
int x;
cin>>x;
int ar[x];
my g++ (gcc) compiler on linux refused to create an array without a fixed size , however using the same code on windows on dev-cpp it was complied and executed , also it allowd me to create and use the dynamic array , i thought it was a compiler bug , however when i restarted and returned to g++ it compiled and executed the code although it never did before i tried the code on windows , how can that be and is it dangerous ?
View 5 Replies
View Related
Feb 14, 2015
Im trying to create a function that searches my array for a specific string, and then displays that string and the other content associated with it. I'm basically searching for a keyword within an array that has multiple strings with in each element.
View 4 Replies
View Related