C++ :: Not Getting Right Value For Addition
Jan 17, 2013
Code:
#include<iostream.h>
#include<conio.h>
class vector {
float x_comp1,y_comp1,z_comp1,x_comp2,y_comp2,z_comp2;
float add_x,add_y,add_z;
[code]....
Now the problem is that when i run the program, i get correct value of the two vectors, but i am not getting the right value for the addition...it might be the x_comp1 and so on are not getting those values even i am assigning them..
View 4 Replies
ADVERTISEMENT
Nov 20, 2013
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
[Code]...
1)What should be the best variable for adding two 6-digit hexadecimal,such as 0034AD,0057EA? I would like to use array of character but it seems hard to handle.
View 3 Replies
View Related
Jan 25, 2015
#include<stdio.h>
#include<conio.h>
void main()
[Code]....
Why it gives output = 6. when i use j=j-9; then it gives output = 65506.
View 3 Replies
View Related
Jun 7, 2014
I need addition array1 array2 in new array before I make this program but the values of array1 and array2 there are in code c# that is worked without problem.
But now i need the user enter the values of arrays, i make that but i failed in addition array1 and array2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyArray {
[Code] .....
View 1 Replies
View Related
Nov 19, 2014
What my ultimate goal here is to make a program that asks the user how many numbers they would like to add followed by asking the user what numbers they want to add. I want the amount of numbers they can add to be infinite and have the loop continue adding the numbers until it reaches the final number. I just need to know how to do this.
Here's my code:
#include <iostream>
#include <string>
using namespace std;
int main() {
//variables
int amount;
float num;
float sum;
[code]....
View 3 Replies
View Related
Sep 29, 2013
i new to c++ programming. i have a program due soon in vector addition. i am to design should be able to add vectors with certain magnitude and direction and give its resultant magnitude and direction (i know how to do this mathematically but programming is not working. the user should be able to select how many vector he/she wants (i don't know how to do this, so i added 3 vectors). here's my work - i did this purely algebraically. it's still incomplete but it compiles. my "if else" statement also doesn't respond correctly.
#include <iostream>
#include <string>
#include <vector>
#define PI 3.14159
#include <math.h>
std::vector<int> v; // declares a vector of integers
using namespace std;
[code].....
View 4 Replies
View Related
Jul 7, 2014
I'm working on a matrix class and I've hit a few snags. Here's what I've got so far:
Matrix.h
#include <iostream>
#include <conio.h>
using namespace std;
class Matrix {
private:
int matrix[50][50];
[Code] ....
Where I have questions is in implementing the addition and subtraction bits into the class itself. I understand that I'm going to have to do a copy operation (this from reading in C++ Primer Plus 5th Edition). Right now I'm just after adding/subtracting as the rest will be variations on the same theme.
So, here it goes:
As I understand the problem, I need to pass my two matrices as arguments to an addition function. This is going to involve having to copy the values of the two existing matrices into temporary matrices within the addition function, then I'll add them, and store them in a new matrix which will be my return value. So...something like this:
int Matrix::matrixAdd(int R, int C, const Matrix & matrix1, const Matrix & matrix2) {
int sum;
Matrix matrix;
for (int i = 0; i < R; i++)
[Code] ....
I do end up with errors there...C2240, and C2662. Again, I'm new to working through this, but that's what I've got. My idea is that I'm passing the maximum size of the array as defined by the user, in this case a 2x2 array, it'll cycle through and add up to that imposed limit...I went 2x2 because it's small enough that testing doesn't drive me up a wall.
View 14 Replies
View Related
Feb 26, 2013
How exactly did u accept it as a string? i mean did u use ascii values or anything? and what was your code for keeping track of carry?
View 1 Replies
View Related
Feb 28, 2013
Below is a code that is used to calculate complex numbers (a+bi, where i = sqroot (-1)) through multiplication and addition.
However, on my output file, no Header is being printed; the only thing that is being printed is "8 + 7i + = "
"complex.h" is included at the end of the code.
Code:
// Trey Brumley// CMPS
// Dr. Tina Johnson
// March 1, 2013
// Program 2: Classes
// This program will demonstrate the use of classes by using a custom "complex-number" (a+bi) class.
[Code] ......
View 4 Replies
View Related
Feb 23, 2013
I'm writing an addition and subtraction calculator that takes input as: 5+6-3+2. You should be able to add or sub as many numbers as you want. I want the while loop to stop when the user hits enter. I put the getchar() function to catch the and break the loop but it is also swallowing the '-' sign, which I want to use to subtract and is instead adding the numbers with "sum+=number". How can I get around that?
Code:
#include <stdio.h>
int main(int argc, char *argv[]){
int number, sum = 0;
[Code]....
View 3 Replies
View Related
Apr 24, 2013
I have to write a code in which the addition of prime number gives the number user input..
for example if user enters 10 then
7+3 = 10
2+3+5 = 10
View 2 Replies
View Related
Apr 28, 2015
I have two questions that are related to each other. The first one is about overloading the addition operator.
I have defined a struct as the following:
Code:
#include <iostream>
#include <string>
struct Sales_data {
[Code] ....
I then overloaded the I/O operators so I could print to the screen information related Sales_data.
Code:
// overload ostream in order for cout to work
std::ostream& operator << (std::ostream & out,
const Sales_data & cSales_data) {
out << cSales_data.bookNo << ", " << cSales_data.units_sold << ", "
[Code] ....
My first issue is with overloading the addition operator. Everyone works correctly except for std::cout << item << std:endl; will no not output the ISBN number only the units_sold and revenue when added together.
Code:
// addition operator rules
Sales_data Sales_data::operator + (const Sales_data & data2) {
units_sold += data2.units_sold;
revenue += data2.revenue;
return *this;
}
Now here is the code in its entirety
Code:
#include <iostream>
#include <string>
// Sales_data structure
struct Sales_data {
std:: string bookNo;
unsigned units_sold = 0;
[code] .....
After total = total + item;, I would like to print the total for this particular ISBN. However, I only get: blank, total units, total revenue where blank is where the ISBN would go but doesn't print after addition. My second question has to do with comparing the ISBN's of the books entered during the while loop. I would like to do something like
Code:
if (item_i.bookNo == item_i+1.bookNo) {
total = total + item;
} else {
std::cerr << "Books entered must have the same ISBNs" << std::endl;
}
Unfortunately, I cannot figure out how to set up a comparison of the bookNos. If I used #include <casset> in the overload + rule, it will immediately exit since I have no way to compare the ISBNs.
View 3 Replies
View Related
Jan 12, 2015
1.What would regex pattern look like for addition of integers?
2.What would regex pattern look like for subtraction of complex numbers?
View 1 Replies
View Related
Jan 26, 2012
I need to create a function that performs the addition of x days at a time, taking two integer values, the first being a date (yyyymmdd format) and a number of days to add / subtract that date.
How can I perform validation if the entire amount received is a valid date and how can I add x days of that date?
View 8 Replies
View Related
Feb 17, 2012
Below is a program that generates random Addition for Subtraction problems depending on the user's choice. The user is prompted to input an answer and then it keeps your score. If you want to quit you just press zero.
Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
#include <string>
using namespace std;
int menu();
bool addition(int &reward); // function to return truth values
[Code] ....
View 14 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