"Write a program that prompts the user for an integer number from the keyboard, and store it in a variable num. After each number is typed in, add num to a total.
Do this six times, each time adding num to a total. (Be sure to reuse the same variable named num for each of the six numbers entered.) When all six numbers have been entered from the keyboard, calculate an average. Display the total and average calculated. "
Here is what I have so far:
Code:
#include<stdio.h>
int main() {
int num, total1, total2, total3, total4, total5, total6, avg;
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 am facing a problem which i could not obtain the total numbers which is greater than the average value. For example:
#include <iostream> using namespace std; int main (){ int size , count; double no, max, min ,total, sum , average;
[Code] ....
In this case im able to compute the average of the numbers but when it comes to capture the total of numbers which is greater than the average value, how to compile the code , because the average number is only been compute once all the value capture by the input of user is sum up.
The program requires the user to enter 10 integers then print the total no. of even integer,highest even integer, lowest even integer then total no. of odd integer,highest odd integer, lowest odd integer
I already got the total no. of even integer and total no. of odd integer. But I don't know how will i get the highest even integer, lowest even integer and highest odd integer, lowest odd integer.
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;
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:
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++)
I'm a beginner at c++ and I need to write a program that reads a set of integers and then finds and prints the sum of the even and odd integers. The program cannot tell the user how many integers to enter. I need to have separate totals for the even and odd numbers. what would I need to use so that I can read whatever number of values the user inputs and get the sum of even and odd?
Every time I run if(color=="1") it's supposed to add 1 to redTotal. However, every time I run if(color=="1") if get 1 for redTotal every time.
(Write a program that provides the option of tallying up the results of a poll with 3 possible values. The first input to the program is the poll question; the next three inputs are the possible answers. The first answer is indicated by 1, the second by 2, the third by 3. The answers are tallied until a 0 is entered. The program should then show the results of the poll—try making a bar graph that shows the results properly scaled to fit on your screen no matter how many results were entered.)
Code: #include <iostream> #include <string> using namespace std; int main()
I am trying to write a function that accepts two arrays as arguments.
The result is to get all values in both arrays and return the total value to the calling program.But when I run the program the total value is not what I expected.
#include <stdio.h> #define MAX 3 int array_1[MAX], array_2[MAX], count; int total(int narray_1[], int narray_2[], int lenght); int main(void) { for (count = 0; count < MAX; count++)
How to total the values that are put in during the loop. For this program I need to add up the values the user inputs and then display them after the loop. Here is what I have:
#include <iostream> #include <iomanip> #include <string> using namespace std; int main() { const int firstQuiz = 1, lastQuiz = 4; int quiz, quizGrade; for (quiz = firstQuiz; quiz <= lastQuiz; quiz++)
Draw the total of a passed value, or value in general, without checking how many values there are individually.
Here's a pseudo-example:
int aliens = 10; // This should be changed as desired. void drawaliens(int value) { aliens.draw(value); // Instead of having a test of how many to draw, draw the amount there is from one check }
I want to draw the amount of aliens passed or called to the alien draw function.
However, I don't want the function to check every possible value of aliens which could be passed before drawing, and just check the value once and draw that value.
IF x ALIENS, DRAW x ALIENS instead of...
IF 1 ALIEN, DRAW ALIEN(1); IF 2 ALIEN, DRAW ALIEN(2); IF 3 ALIEN, DRAW ALIEN(3); .... and so on.
If there can be hundreds of aliens, it seems impractical to check every single possible value before drawing, and just check the value and draw that value.
I am beginner in C++ programming. I having a problem to show the output of all the element i store at a array called total_price. the output become unreadable.
#include <iostream> using namespace std; int main () { float price[1]={0}; int qty;
Basically, I am designing a form that shows all of the services a mechanic performs, and then it is supposed to calculate the total based on the selections made.
HOW do I use those check boxes to calculate a total? I am supposed to use value-returning methods that solve for the parts cost, flush charges, tax charges, misc costs, etc. Ive attached a picture of the form thus to make sense of what I'm trying to describe.
The project has to ask for ten grade inputs with a "for" loop and depending on the grade you input you either receive an "outstanding", "satisfactory", or an "unsatisfactory" output. At the end of the program I am supposed to display the total count of each category, total count of all categories and the average grade. The problem I have is that I cannot figure out a way to calculate what I have to display.
#include <iostream> using namespace std; int main() { double grade = 0; int g; for (g = 0; g < 10; g ++) {
I am trying to get 2 numbers from 2 textboxs and get a return sum in the third textbox. the strange thing is that i got it to work with this code that i am going to provide on the last app i worked on, now on the new app i am on it doesnt work at all.. I am not getting any Errors, just shows a zero when i calculate to the sum of the total textbox.
int sum1 = 0; int sum2 = 0; int result = 0; if (int.TryParse(txtPrice.Text, out sum1) & int.TryParse(txtQuantity.Text, out sum2)) result = sum1 * sum2; txtSubTotal.Text = result.ToString();
I'm supposed to write a program to read a text file and display the following:
a) alphabetic letters //finished with b) digits // finished with c) other characters that are not alphabetic letters and not digits //finished with d) total characters read
The bold part above confused me, by total characters, does it mean the alphabetic letters + other characters? how would I put that in my code?
Code: #include <stdio.h> int main (void) { int curCh; int countCh = 0;
Given a structure book defined as follows and an array lib of books
Code: struct Book{ char title[100]; char author[100]; int price; struct Book *nextedition; };
struct Book lib[1000]; I'm going to write a function to compute total price of books by a given author including all books which are future editions of his book, even if the author of that future edition is NOT the specified author. title author price nextedition Book1 Author1 25 &lib[2] Book2 Author2 20 NULL Book3 Author3 30 &lib[3] Book4 Author1 35 NULL For the example above, given the author "Author1", the function should return 90 (=25+30+35), and given the author "Author 3", the function should return 65 (=30+35).
So here's my attempt:
Code: int totalPrice(char author[100]){ int total=0; for (i=0; i<numbooks; i++) if(strcmp(author, lib[i].author==0))
[Code] ....
What I'm trying to do is finding the first book in the lib of the specified author using for loop and then let the while loop do the rest. However, it seems the price is over-counted after each iteration of the for loop but I don't know how to fix it.
I missed last class on doing void functions because I got sick and im completely lost! ive being using the texts book example for a reference but its not running !
The output should look similar to this:
how much was your shirt? 20 shirt 20.00 tax =1.20 the total 21.20
Code:
include <iostream> #include <iomanip> using namespace std;
Write a program that simulates an adding machine. When a zero is entered it should print the subtotal of all the numbers entered from the last zero that was entered and reset the subtotal. When two consecutive zeroes are entered it should print the total (not the subtotal) of all the numbers entered and terminate the program. Example:
Be careful this program needs a bit more thought than you might think at first. To get full credit you must make sure it also works for the 0 - 0 case. Example:
0 subtotal 0 0 total 0
The problem is, after I enter the integers and type 0, it shows the subtotal which is what I want; however, when I type more integers and type another 0 to see the subtotal again, it shows the total instead. The subtotal should reset whenever a single 0 is typed and the total should only show when two 0's are inputted simultaneously. Also, after the user enters two 0's simultaneously and views their total, I want the program to exit by saying "press any key to exit." Is there a special name for that to happen? Here is my code:
#include "stdafx.h" #include <iostream> using namespace std; int main() { int subtotal = 0, total = 0, number = 0; bool input_zero = false;