C :: Addition And Subtraction Calculator That Takes Input?

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


ADVERTISEMENT

C/C++ :: Matrix Class - Addition / Subtraction

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

C# :: Regex For Addition Of Integers And Subtraction Of Complex Numbers

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

C++ :: Generates Random Addition For Subtraction Depending On User Choice

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

C++ :: Creating Binary Calculator - Output Operation Of Subtraction

Feb 10, 2014

I need to create a binary calculator that outputs the operation of subtraction whenever you input 2 4 bit binary numbers. For example:

If I enter

1000
- 0111

View 1 Replies View Related

C++ :: Calculator That Takes Two Large Numbers In Linked List Then Ask User To Add Or Subtract

Dec 30, 2012

What I'm trying to do is make a calculator that takes two large numbers in a linked list then ask the user if they wish to add them or subtract them.

#include<iostream>
#include<string>
using namespace std;

class Node {
public:
int value;
Node * next;

[Code] ....

View 5 Replies View Related

C++ :: User Input Data About Percentages To Calculate Final Grade - Addition Error?

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

C :: Menu For A Project That Takes String Input And Does Whatever Option Specified

Feb 13, 2014

I have a menu for a project that takes a string input and does whatever option you specify. It works perfectly EXCEPT when it goes through the while-loop (while you didn't say quit the menu reloads). It will spew out all the text in the menu like a bulimic teenager. Then it reloads properly and asks you for an input like nothing happened. While this is not a fatal error (code still functions)...

Code:
#include <stdio.h>
#include <math.h>
#include <string.h>

double aa=0, ab=0, ac=0, sa=0, sb=0, sc=0;
char a1[13], o1[]="AAS

[Code] .....

View 2 Replies View Related

C :: Make Program That Takes Number Input From Tuser?

Jul 27, 2013

I have to make a program that takes a number input from the user and prints the corresponding fibonacci sequence number. For example, for the input of 3, it should print 2 since the third term in the fibonacci sequence is 2.

I am not sure how to do this so for my attempt, I used the formula found in this website. A Formula for the nth Fibonacci number

Here is the program so far. It doesn't produce the correct output.

Code:

#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#include "math.h"

[Code]....

View 11 Replies View Related

C :: Program That Takes A Large Text File As Input

Nov 7, 2014

I am writing a spell checker for a exercise for a class I am taking online. I have to load a huge text file of 143092 words into a hash table.

The program segfaults on word number 63197. Is there a way to debug this in gdb without having to step threw the function 63197 times.

View 3 Replies View Related

C++ :: Program Which Takes Date And Time Input From The User

Jan 20, 2013

I am writing a C++ program which takes date & time input from the user. This is then parsed into a struct such as:

struct time
{
short year;
short month;
short day;
short hour;
short min;
};

My question is: how can I convert such a struct into a time_t object, which is an unsigned long giving the time as the number of seconds elapsed since the epoch Jan 1st 1970, 00:00, as set out in time.h.

I am wondering if this can be achieved using the standard library, or whether I just need to write a function to perform the appropriate arithmetic.

View 2 Replies View Related

C++ :: Program Which Takes Input From User And Write It To A File

Jan 15, 2013

A program which takes input from user and write it to a file then it reads data from that file then it should search for specific data such as email adresses or url etc.

View 1 Replies View Related

C++ :: Function That Takes Two Input Arguments And Provides Two Separate Results To Caller

Apr 20, 2014

Write a function that takes two input arguments and provides two separate results to the caller, one that is the result of multiplying the two arguments, the other the result of adding them.Since you can directly return only one value from a function, you'll need the second value to be returned through a pointer or reference parameter.

Code:
#include "Code.h"
#include <iostream>
#include <string>

double x, y;

[Code] ....

View 3 Replies View Related

C++ :: How To Write A Function That Takes Two Linked List As Input Arguments

Dec 7, 2012

How do I Write a function that takes two linked list as input arguments these linked list contain numbers like this:

num1->3->5->2->NULL (assuming that number 1 is 352)
num2->4->3->9->1->NULL (assuming that number 2 is 4391)

The function should return 1 if num1 points to a linked list which represents a smaller number than the number pointed to by num2 linked list. Otherwise, it returns -1. If both linked list point to exactly the same number, returns a 0.

View 3 Replies View Related

C/C++ :: Program Takes Integer Input And Displays Each Digit On New Line From Right To Left

Jan 23, 2015

I'm trying to create a program that takes an integer input and displays each digit on a new line from right to left.

An example of this would be:

Enter an integer: 657
Digit (1): 7
Digit (2): 5
Digit (3): 6

So far I have this:

#include <stdio.h>
#include <math.h>
int main() {
int i, input, output;
printf("Enter an integer: ");
scanf("%d", &input);
if(input == 0)
printf("Digit (1): 0");

[Code] ....

It works perfectly fine, but I just learned that I am not allowed to use the #include <math.h> so I have to take out floor, log, and pow.

I'm pretty sure I have to do some sort of while or for loop to get the results, but how to do it.

View 6 Replies View Related

C :: Calculator - Input Specific Number?

Feb 11, 2013

In my calculator, I am trying to make it so that you put enter 1 to add, 2 to subtract, 3 to multiply, and 4 to divide. I am facing the issue of making it so that you must enter a number, however instead of it being any number, it must be 1, 2, 3, or 4, and if it is not any of those numbers, you must re-enter the number. Here is a little snippet of my code:

Code:

printf("Please enter 1 to add, 2 to subtract, 3 to multiply, or 4 to multiply: ");
while (scanf("%d", &input) != 1) {
while (getchar() != '
');
printf("Invalid option. Please try again: ");

[Code] ....

how I can make the loop affect specific numbers.

View 4 Replies View Related

C++ :: How To Allow User To Input Operator Into Calculator Function

Aug 24, 2014

How I can let the user input a certain operator into this calculator function?. I would like to use cin to input the operator if possible because it is one of the only input commands I know.

// Calculator.cpp : Defines the entry point for the console application.
// Calculates the value of two numbers based on the four main operations.

#include "stdafx.h"
#include <iostream>
int add(int x, int y);
int subtract(int x, int y);
int multiply(int x, int y);
int divide(int x, int y);

[Code] ....

View 1 Replies View Related

C++ :: Federal Tax Calculator Based On User Input

Apr 17, 2014

I am doing an assignment that is to calculate the federal tax based on the users input. I am not entirely sure what it is doing, but it is definitely not what I want it to do. I commented out the loops because they seemed to have caused a problem, but there is still problems that are making the program do something else. Here is my code:

#include<iostream>
#include<string>
using namespace std;
double getData();
double taxAmount();

[Code] ....

Functions just seem like they are not my thing. It never gets to the second function to do the calculations and then return to main to display the results.

I tried changing the code to a switch(status) with a default: at the end that looped the "please try again" but for some reason, that was a fail, it created an endless loop.

View 15 Replies View Related

C/C++ :: Simple Calculator - Clear Screen Following User Input

Dec 10, 2014

I am working on a simple calculator in C++ .... All works fine with the calculator up until the requirement for the user to input "do you want to go again y/n" .... What i want to happen is the screen to clear down and reloop to the enter name part....but i can't get it to do that

Program Description: To write and develop a programme where a user can input a cost or price of something before VAT our program must then process the input number and must output the price with the original value plus VAT

#include <iostream>// I must use this to start my programming
#include <string> // I have added this for the extension task so the user has to input their name
#include <iomanip> // this is to manipulate the text
#include <stdlib.h>
using namespace std; // using the "using namespace std" shows that i will be using standard text throughout this programme

[Code] .....

View 5 Replies View Related

C++ :: Subtraction Of Two Integers?

Apr 18, 2014

I am working on an assignment where I have to subtract two very large integers. How can I write it's code provided that I have both numbers in a character array with each index holding a fraction of the original number. Like if I have a number 123456789 in an array then

arr[0]='1';
arr[1]='2';
arr[2]='3';
arr[3]='4';
and so on. n

nNw if i have to subtract this number from an other number, how can I do that?

View 4 Replies View Related

C/C++ :: Subtraction - Two Time Intervals

Mar 12, 2014

I am looking for simple code that subtract two time interval. I have time t1=5hour 30 minute and other time in 24 hour format. This code i written but it not working as expected

main() {
intTime1;
intTime2;
int hour=10;
int minute=5;
int second=13;
int h;int m;

[Code] ....

Is there any easy way of doing above code. Above two code section not working....

View 8 Replies View Related

C++ :: Variable Length Integer Subtraction

Aug 24, 2013

On a controlled buffer of unsigned char it is possible to do subtraction faster than if you followed standard mathematical rules, here is an example:

typedef unsigned char uchr;
uchr num1 = 5; //00000101
uchr num2 = 3; //00000011
num2 = ~num2; // 11111100
++num2; // 11111101
uchr num3 = num1 + num2; // 00000010(2) - computer truncates result to fit char

Since you will be working with a buffer you don't even need to worry about truncating the final bit because the add function will not be able to reach it - unless it is given the ability to grow the buffer in which case you just set the bit to 0 yourself

View 8 Replies View Related

C++ :: Perform Subtraction Between Two Objects And Put Result In Third Object

Sep 19, 2013

trying to understand operator overloading, and i wrote some code just to define a "-" operator to do a simple subtraction. SO, i wrote a program that can perform a subtraction between two objects and put the result in the third object. now I Just cant show the result on the console. And also can anyone define the meaning of [b1.x], like I want to know am I assigning the value to the "b1"object or the x variable? This is a very concept that I need to understand.

#include<iostream>
using namespace std;
struct Ok
{
int x;
int y;
};

Ok operator-(const Ok& a , const Ok& b)

{
Ok result;
result = (a - b);
return result;
}
int main()

[Code]...

View 2 Replies View Related

C++ :: Specific Iterator Type - Find Distance By Simple Subtraction

Sep 24, 2014

I have a templated container that defines a forward iterator.

Calling std::distance on these iterators will generate code that will count the number of iterations it takes to get from the first parameter to the second, by repetitively incrementing.

Internally, the iterators can easily find the distance by a simple subtraction.

What I want to do is overload std::distance for these iterators so that it will take advantage of the simple calculation rather than repetitive increments.

The simple solution of course would be to make the iterators random access, but this would require that they support functionality that is not 'logical' for the container. Access to the container only makes logical sense when iterating one item at a time in the forward direction.

Code:
#include <iterator>
template <typename T>
class Container {
public:
class iterator : public std::iterator<std::forward_iterator_tag, T> {

[Code] .....

View 2 Replies View Related

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 View Related

C++ :: Convert To Hexadecimal And Hex Addition

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







Copyrights 2005-15 www.BigResource.com, All rights reserved