I am having an error at line 21. Specifically the code where it says "list[num]=x"
How am I able to fix this code to do what I want? The purpose of my program is to enter in positive numbers in an array (and having it end when 0 is typed) My program also accepts negative values but will ignore them when it is outputted. I believe I have all the code right except for line 21.
#include<iostream>
using namespace std;
const int ARRAY_SIZE(25);
void read_list(const int list[],const int ARRAY_SIZE);
int main() {
int list[ARRAY_SIZE];
read_list(list, ARRAY_SIZE);
I have a problem with my assignment. I would like to ask how to transfer positive and negative values from array temperature to arrays positive and negative?
#include <iostream> #include <iomanip> using namespace std; int main(){ int n=0, d=0, temperature[20], sum; int positive[], negative[]; float avg;
Write a program which reads a stream of numbers from a file, and writes only the positive numbers to a second file. The user should be prompted to enter the names of both the input file and output file in main(), and then main() will open both files. Another function named process() must then be called to read all the numbers from the input file and write the positive numbers to the output file. Note that you must pass the open stream variables for each file as arguments to the process() function, and that you need to (always) double check that the files opened successfully before using them.
This is what I have so far but its not working out!
#include <iostream> #include <fstream> #include <stdlib.h> using namespace std; int process(ifstream &inf, ofstream &outf);
Write a function that raises an integer to a positive integer power. Call the function x_to_the_n taking two integer arguments x and n. Have the function return a long int, which represents the results of calculating x^n.Here's my code:
Code:
#include <stdio.h> long int x_to_the_n(int x, int n) { int i; long int acc = 1;
for(i = 1; i <= n; ++i) acc *= x; }
[code]...
It compiles OK, but when I run it the program stops after entering the number (x) and power (n).
Write a program asks the user for a positive integer value and then prints out all perfect numbers from 1 to that positive integer. I have been trying for some time, i found a way to check if its a perfect number or not but could not find a way to prints out all perfect numbers from 1 to that positive integer. I am here so far.
#include<iostream> #include<iomanip> using namespace std; int main(){ int n,i=1,sum=0; cout<<"Enter a number: ";
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..
Write a C++ program that reads in two positive integers that are 20 or fewer digits in length and outputs the sum of the two numbers.
Your program will read the digits as values of type char so that the number 1234 is read as four characters '1', '2', '3' and '4'. After they are read into the program, the characters are changed to values of type int. The digits will be read into a partially filled array and you might find it useful to reverse the order of the elements in the array after array is filled with data from the keyboard.
Your program will perform the addition by implementing the usual pencil and paper addition algorithm. The result of the addition is stored in an array of size 20 and the result is written to screen. if the result of the addition is an integer with more than maximum number of digits(that is more than 20 digits) then your program should issue a message saying that it has encountered "integer overflow".
You should be able to change the maximum length of the integers by changing only one globally defined constant. Include the loop that allows the user to continue to do more additions until the user says the program should end. What I have so far is
#include <iostream> #include <cstdlib> using namespace std; void reverseArr(int a[], int liu); void addLargeInt(int a1[], int liu1, int a2[], int liu2, int sum[], int& liu_sum); int main() { cin.get(next);
So I have to make a program that allows the user to enter both positive and negative numbers and the program is suppose to calculate the sum of only the positive values while ignoring the negative values. Also it is to be a sentinel-controlled loop with a number ending the set of values.
i have a program that works, but now I am trying to get function1() to work. What it has to do is bring in the array and populate it with random letters. I don't know much about functions.
Code:
#include<stdio.h> #include<stdlib.h> #include<time.h> #define maxrow 20 //defines maxrow as a constant of 20 #define maxcol 30 //defines maxcol as a constant of 30 }
Description: Use functions and structures to simulate storage in a warehouse
*/ #include <cstdlib> #include<iostream> #include<cmath> #include<iomanip> #include<string> using namespace std; struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"
[code].....
I keep getting a linker error on every function. what am I doing wrong?
I'm having trouble with passing a character array between functions of the same class. I have a function, buildGraph, that calls function getNextLine. The getNextLine essentially just retrieves the next line of an input file and stores it into a "char line[80]". However when I try to use "line" in my buildGraph function, it has nothing in it.
Here's my code:
Class #define NUMNODES 10 using namespace std; #pragma once class Prog3Graph
I need to create subfunctions to do basic Matrix mathematics (addition, subtraction, etc.) I need to be able to pass bot of my Matrices to subfunctions. I started with the addition sub function and I cant get the code to run. I keep getting expected primary-expression before ']' token error for line 75.
#include <iostream> #include <stdio.h> using namespace std;
I am working on incorporating a function in to an already existing piece of code, I have incorporated the function fine as far as I am aware.
The problem I have is that I am trying to pass two int arrays to the function, so that i can manipulate and compare them "the values will be changed the originals cannot be changed"
I am having trouble pulling the information out of the already created array, I am able to pass the pointer reference for the single value which is not exactly what i want "best_prog".
My function is below I have commented the memcpy parts and also the majority of the code isn't there cause it is not needed to see make the copy work.
int edit_distance(int index) { struct prog *progp = &population[best_prog]; /* The struct of best prog not sure if i need one for the other prog I am trying to compare it with the one below doesn't work as intended.*/ //struct prog *progp = &population[]; int editdistance = 0, ar1 = 0, ar2 = 0, a = 0, b = 0, j = 0, x = 0;
// Music Shuffle Program // This program takes an array of strings and randomly permutes their order. // This allows us to generate new song shuffles. #include <iostream>
I'm working on a homework assignment that asks me to roll two die a user given number of times, find the roll sums, and a few other things. I'm working on it one module at a time and I'm running into two big problems so far.
The first problem is that my int variable rolls changes to a number within the random number generator range of numbers after I run rolldie. I got around this by making a const equal to the user entered value of rolls just so that I could continue developing the program.
My second problem is that the values of the arrays resultsOne[] and resultsTwo[] are changed after running findsum(). Why this is happening and I even tried passing them as const, but that changed nothing. We just started learning about passing arrays to functions, so there might be something big that I'm missing.
Code: #include <iostream> #include <cstdlib> using namespace std; void rolldie(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo); void findsum(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo, int tossSums[], int sizeOftossSums);
im supposed to create a program that reads in a list of integers from the terminal and writes the negative numbers to one file and the positive numbers to another file.
i got most of it doen but for some reason its not writting the negative numbers. on what im doing wrong?
#include <iostream> #include <fstream> #include <string> using namespace std; int main(){ int pos_num = 0; int neg_num = 0; int positive_numbers = pos_num % 5;
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; }
I have an Array of [3] [3] and by default the numbers will be in following format, which is not visible -
1 2 3 4 5 6 7 8 9
I need to get the numbers from User, example -
0 4 0 9 1 0 5 0 7
if a User fills random numbers like above, then my program needs to fill the '0's with the missing numbers from 1 to 9 in an ascending order as below -
2 4 3 9 1 6 5 8 7
This is my problem and i need a logic for this in C++.