subject

Task:

We want to make a simple calculator that can add and subtract integers and will accept arbitrarily long mathematical formulas composed of symbols +, -, and non-negative integer numbers.

Imagine you have a file formula. txt with the summation formula such as:

100 + 50 - 25 + 0 + 123 - 1
If you redirect the file into your program, it should compute and print the

$ ./calc < formula. txt
247
Specifically, write a program calc. cpp that reads from the cin a sequence of one or more non-negative integers written to be added or subtracted. Space characters can be anywhere in the input. After the input ends (end-of-file is reached), the program should compute and print the result of the input summation.

Possible input that has spaces and characters:

1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 +
1 + 1 + 1 + 1
Possible output: 16

You can use >> operator to read the numbers and the +/- characters, because >> will be skipping all spaces between the input terms.

WHat would the program be here? How would i successfully read in the file and get the right output?

Thanks

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:00
I'm taking a class on how to make a movie, and it offers some apps that would be in the process. the thing is, i don't have any of those ha. if you have any tips on some apps i could use, that would be awesome. i don't have an iphone, so don't suggest any apps like imovie. i know that this is a weird question, but it would be super for me. : )
Answers: 2
question
Computers and Technology, 23.06.2019 21:30
Write a fragment of code that reads in strings from standard input, until end-of-file and prints to standard output the largest value. you may assume there is at least one value. (cascading/streaming logic, basic string processing)
Answers: 3
question
Computers and Technology, 24.06.2019 07:00
Guys do you know sh27 cause he hacked me : ( pidgegunderson my old user
Answers: 2
question
Computers and Technology, 24.06.2019 13:30
What process should be followed while giving a reference? sam has given a reference of his previous manager in his resume. sam should him in advance that the potential employers will him.
Answers: 1
You know the right answer?
Task:

We want to make a simple calculator that can add and subtract integers and will ac...
Questions
Questions on the website: 13722361