C/C++ :: Getting Total Value Of 2 Arrays?
Mar 9, 2014
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++)
[code]....
View 1 Replies
ADVERTISEMENT
Apr 16, 2013
Code: i am trying to display the information in the array as a table and add the total rows and the total colums separately
#include<stdio.h>
int main(void)
{
int row, col;
[Code].....
View 1 Replies
View Related
Jan 14, 2015
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()
[Code]....
View 4 Replies
View Related
Jan 22, 2013
"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;
printf("Enter first number:");
scanf("%2d",&num);
[Code] .....
View 2 Replies
View Related
Oct 23, 2014
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++)
[code]...
View 4 Replies
View Related
Apr 8, 2013
i am doing a sales commission program to run a counter on the commission calculated, but the answers can't show on the counter
here's what i've done so far:
#include <iostream>
#include <iomanip>
#include <cmath>
[Code].....
View 2 Replies
View Related
Feb 7, 2015
decTotalAmountOwed = decAmountOwed + decAmountOwed;
This is what i've tried so far. The numbers are supposed to be added together once placed in listbox.
View 8 Replies
View Related
Feb 4, 2014
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.
View 2 Replies
View Related
Feb 28, 2013
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.
View 2 Replies
View Related
Sep 30, 2013
If I entered multiple cin say for variable x, how do I total them all up at the end?
Example: x being the variable.
cin 45
cin 50
cin 22
The total would be 117 but how would I write that in c++?.
View 3 Replies
View Related
Feb 28, 2013
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;
[Code] ....
View 6 Replies
View Related
Apr 25, 2013
how to search and display the total between 2 days without using lots of code
View 3 Replies
View Related
Mar 1, 2015
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.
View 5 Replies
View Related
Feb 15, 2015
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 ++) {
[Code] ....
View 2 Replies
View Related
Oct 3, 2014
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();
View 11 Replies
View Related
Mar 21, 2013
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;
[Code]....
View 1 Replies
View Related
May 7, 2013
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.
View 2 Replies
View Related
Dec 4, 2014
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;
void getShirtCost(double shirtCost);
void calculate(double shirtCost,double taxAmount, double total, double taxamount) ;
void printReceipt(double shirtCost, double taxAmount, double total, double taxamount);
[Code] ....
View 1 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
Mar 28, 2013
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:
1
2
3
0
subtotal 6
4
5
-2
0
subtotal 7
8
0
subtotal 8
0
total 21
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;
[Code] ....
View 2 Replies
View Related
Apr 24, 2013
I am trying to find total gross for department entered but it keeps giving me a total gross for every department and I don't want that. I think its maybe just one word I am missing but not sure. Here's my code
// display record by searching by dept number
void searchByNumber(Staff s[] ,int row) {
double GrandTotalPay=0.0;
clrscr();
cout << "this is Search
[Code] ....
View 2 Replies
View Related
May 11, 2014
How to do recursive function for the following?
RecursiveComputeRouteDistance(p1index,p2index,locations,latitudes,longitudes): recursively computes the total distance between all waypoints (route) using computeDistance function to compute the distance between two adjacent points. You need to recursively compute the distance for the base case(s) and the general case(s).
This is my computeDistance function
int computeDistance(double a1,double b1,double a2,double b2) {
const int R=6378136;
const float Pi =3.14159;
float Dist=0;
Dist= ((Pi*R)/180)* acos((cos(a1)* cos(b1)* cos(a2)* cos(b2)) + (cos(a1) *sin(b1)* cos(a2)*sin(b2)) + (sin(a1)*sin(a2)));
return Dist;
}
View 2 Replies
View Related
Mar 26, 2013
I have a program that needs to calculate the total for three stores payrolls.
Inputs would be the three stores payrolls
Output would be the total of all three
I HAVE to use the while statement.
I have also read the articles on the while statement on here and on other sites. I'm having trouble because every site I've seen so far has only been giving examples of numbers(like counting down or repeating a statement so many times).
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
//declare variables
int storePayroll = 0;
int totalPayroll = 0;
int storeNum = 0;
[Code] .....
View 6 Replies
View Related
Dec 21, 2014
I am having trouble getting the running total to in this code, it runs but in case 4 the part with the call for the running total is just giving me the same number 589505315. Hope it is just a simple overlook on my end like usual. Here is my code.
#include <iostream>
#include <iomanip>
using namespace std;
int Show_Menu (); //To show Menu
int Purchase_Ticket (); //To purchase ticket
void Show_Chart (); //To show the seating chart
const char FULL = '*'; //Seats taken
const char EMPTY = '#'; //Seats open
[Code] .....
View 1 Replies
View Related
Oct 28, 2014
i have a list view, which is shown below as an example, i am hoping to achieve to find out a method of adding up the values in the Sub2 Column in C#. Then i will output it to a label on my form. So the total should be 14. But i don't have a pre-defined number of rows, and thats what i needs to be. I thought of something like
label1.Text = ListView1.SubItem2.text
But no such luck....
Index Item Sub1 Sub2
-------------------------------------------
0 IE Micro 8.0
1 FF Mozil 3.0
2 Safari Apple 3.0
View 14 Replies
View Related
Feb 25, 2015
How can i count total number of each topic separately? For example total number of topic 1 between all nodes. To begin enter 10 and 7 to initial node number and number of topic.
#include <iostream>
#include <vector>
#include <list>
#include <stdlib.h>
#include<time.h>
#include<iomanip>
#include <iostream>
#include <string>
[Code] ....
View 1 Replies
View Related