C++ :: Plus Or Minus Notation

Aug 4, 2013

Is there a simple notation to check if a value is within a plus or minus range?

E.g.
//I read a value A. delay(50); //Read value again -calling this value B delay(50);
//Read value again -calling this value C delay(50); //Read value again -calling this value D delay(50);
//Read value again -calling this value E
Check IF first value A is within 5 of the value B and within 5 of value C, etc.

I can think of a few round about ways of doing this but is there any simple "equals to plus or minus" notation? (what I actually want to do is to check a lot more values than this and it will get very complicated with any of my solutions)....

View 4 Replies


ADVERTISEMENT

C++ :: Write Program To Convert Time From 24-hour Notation To 12-hour Notation

Dec 10, 2013

Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following function: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the input, and function(s) to display the results. (For 12-hour time notation, your program must display AM or PM.)

Answer:

#include <iostream>
#include <iomanip>
#include <cmath>

[Code]....

It is showing error because may be I was not able to put that if statement inside any function. find out the error sand complete the program with corrected code.

View 2 Replies View Related

C++ :: Add And Minus From Text File Not Giving Right Value

Feb 5, 2014

I'm creating a bank system. So I know to make a deposit to the balance, which add ups what is the balance to i have add.

When i run the deposit function, its work well in some ways. If balance(text file) has the value 10, add i addSum 20, the balance will become 30, same as the text file will become 30. so its work well to add positive number.

double deposit(double balance){
double addSum = 0;
system("CLS");
cout<< "Welcome to deposit."<<endl;
cout<<"Enter a sum you wish to add to your account:";

[Code] .......

When I withdraw from 30 which is the balance, then i takeSum, for example i take away 30. The balance will become 30 - 30 = 0

When i make another withdraw from example -150, it will be -150.

Which shows correct.

But when i make a deposit from -150 and i addSum 130, the balance shows -500, and it should had been -20.

double withdraw(double balance) {
double takeSum = 0;
system("CLS");
cout<< "Welcome to withdraw."<<endl;
cout<<"Enter a sum you wish to take away from your account:";
cout << balance << '

[Code] .....

What is causing this problem, also when function deposit and withdraw close, it goes to readBalance function, should go to menu.

double readBalance(double balance) {
int option;
system("CLS");
cout<<"Welcome to balance."<<endl;
cout<<"Your balance is:"<<endl;

[Code] .....

View 1 Replies View Related

C++ :: Add And Minus From Text File Not Give Right Value

Feb 5, 2014

I'm creating a bank system.

So I know to make a deposit to the balance, which add ups what is the balance to i have add.

When i run the deposit function, its work well in some ways. If balance(text file) has the value 10, add i addSum 20, the balance will become 30, same as the text file will become 30. so its work well to add positive number.

Code:
double deposit(double balance) {
double addSum = 0;
system("CLS");
cout<< "Welcome to deposit."<<endl;
cout<<"Enter a sum you wish to add to your account:";

[code]...

When I withdraw from 30 which is the balance, then i takeSum, for example i take away 30. The balance will become 30 - 30 = 0 When i make another withdraw from example -150, it will be -150.Which shows correct.

But when i make a deposit from -150 and i addSum 130, the balance shows -500, and it should had been -20.

Code:
double withdraw(double balance) {
double takeSum = 0;
system("CLS");
cout<< "Welcome to withdraw."<<endl;
cout<<"Enter a sum you wish to take away from your account:";

[code]...

View 2 Replies View Related

C++ :: T Minus Loops - Variable Index Declaration

Apr 25, 2014

(while)

T minus 10 and counting
T minus 9 and counting
T minus 8 and counting
T minus 7 and counting
T minus 6 and counting
T minus 5 and counting
T minus 4 and counting
T minus 3 and counting
T minus 2 and counting
T minus 1 and counting

Declare the following index before the while loop:

int index = 10;

Correctly code a while statement below using the variable index as defined above, to produce the output shown above.

So this is what my code looks like... I also have to convert this same loop into a do while and for loop. So if I can get this one right I think the others should come relatively easy.

while (int index >= 10) {
cout << "T minus " << index;
index--;
}

View 4 Replies View Related

C/C++ :: Two Arrays Merging Into New Array Minus Duplicates

Mar 9, 2013

I have same question as posted by holla and Iam not sure about merging the contents of 2 sorted arrays into another array without duplication of values.

View 9 Replies View Related

C++ :: Scientific Notation To Decimal?

Mar 12, 2014

I just wrote code that is a program for a relativity calculator. However many of my outputs (because the values tend to be large) end up in scientific notation. Although useful, its not great for the laymen, or nice looking.

How can I change it so that output is not in scientific notation? here is the code:

// This program/converter is designed to find the desired 'real' values using Einstein's theory of relativity

#include<iostream>
#include<math.h>
#include<stdlib.h>

[Code]....

View 1 Replies View Related

C/C++ :: Calculate Postfix Notation

Feb 15, 2015

My program suppose calculate postfix expression.

Ex. 5 4 + 3 10 * + the answer is 39 because if I change it to infix, it's (5 + 4) + (3 * 10)

I need to use vector to compute the value. Here is what I think. First, I save leftmost from the string. If it is a number, I push. If that is a operation, I pop twice and push the result. By doing it until the string is emptied, the vector will only contain the final answer. And here is my code

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
vector<int> stack;
string input;

[Code] .....

When I put 1 1 + or 2 2 +, it showing me a correct answer, but when I put the above example which is 5 4 + 3 10 * +, it shows 30 instead of 39.

View 8 Replies View Related

C/C++ :: Infix To Postfix Notation

Sep 14, 2014

I'm trying to make an infix to postfix notation calculator. The difficult thing is th stack class is custom. It's not to hard to understand, I don't know if the fact that it is that way will not allow me to receive support. The difference is that the pop functions is as such:

stack<char> conversion;
char temp;
conversion.pop(temp);//It receives a parameter and puts the popped element in there.
conversion.peek(temp);//Places the top element in said parameter

not only that... but these are boolean functions. they return true if the operation was completed. So they can be used as conditions.

#include<iostream>
#include<string>
#include<stdio.h>
#include"stack.h"
using namespace std;
int main(void) {
Stack<char> conversion;
string infix,inter,temps;

[Code] .....

The error is that i am mismanaging parenthesis handling and i can't seem to grasp where and how.

An example input is:(35+7)-(9-2)
that input gives me:35 7 + 9 2 ) -
but another input such as :(35+7)/7
outputs as: 35 7 + 7 /. Totally fine.

View 3 Replies View Related

C++ :: Stop Scientific Notation

Jul 15, 2013

double number = 10000000;
int range;//the length of the string result
string result;//holds the number in a string
ostringstream convert; //stream used for the conversion
convert << number;
result = convert.str();

range = result.length();

I'm trying to convert a double to a string and when the number goes to ten million it goes to scientific notation and it shows it in the string. How do I stop it from do that?

View 2 Replies View Related

C :: Program To Print Letters In Given Notation

Feb 11, 2014

I have to develop script in C to print the alphabets in given notation.

Please check the attachment.

View 4 Replies View Related

C/C++ :: Reverse Polish Notation Not Doing Second Operand

Sep 24, 2014

been working on this code til my eyes bled, can not get second operand to work, if i enter 1 2 3 + - it will only return 5 from the addition operand.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

[Code].....

View 5 Replies View Related

C/C++ :: Program For Adding Many Fractions With Sum Notation

Jul 16, 2014

I was trying 2 write a program that would calculate the sum notation of 1/(i^2) with the starting number to be 1 and goes up to the nth term. For instance if the user inputed 3 then the sum would look like 1+1/4+1/9. I somehow made a code but it gets weird numbers which some include negative numbers... when I input a number that is above 5.

#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]) {
int n;
register int i=1;
float b;//For part 1

[Code] ....

For some reason I can't edit printf("%f",/>/>; when I post it as the topic so ignore that part cuz Ik its supposed to be written as printf("%f",/>;

View 6 Replies View Related

C/C++ :: Find Out Scientific Notation Of Numbers

Oct 21, 2014

how i solve this..?

View 1 Replies View Related

C++ :: Output Sorting Error Using Pointer Notation

Aug 6, 2012

My code compiled well(After long Messing up with my head). But, i still not satisfied of my output as i expected. My code ought to sort the object of person comparing their salary. But, its not.

Code:
#include <iostream>
#include <string>
using namespace std;
class person {
protected :
string name;
float salary;

[Code] ....

It doesn't sort the object of class person rather than it prints out the stored value as it is.

View 3 Replies View Related

C/C++ :: Read Arguments From Console For Reverse Polish Notation

Sep 21, 2014

I have this code in order to make a RPN calculator,but im trying to read from the console entering the expression in reverse polish notation,Also I think it will be better to use fgets() instead of scanf since the person can entere something like this 3 2 1 + x

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>

[Code].....

View 7 Replies View Related

C :: Calculate Final Grade By Adding 4 Numbers Minus Lowest Grade And Dividing By 3

Apr 7, 2013

I'm writing a program to calculate a final grade by adding 4 numbers minus the lowest grade and dividing by 3. My knowledge in c is not extensive I thought that a simple assigment operator would do the job but I'm getting a strange large numbers in the execution.

Code:
#include <stdio.h>
#include <stdlib.h>
main(){
int eg, g1, g2, g3, g4, fg, s1, s2, sg;

[Code] ....

View 4 Replies View Related

C++ :: Std List - How To Get Value Of Element 2 Minus Element 1

Aug 23, 2012

I have an std list of type double.. and the list is always guaranteed to have just 2 elements. I need to get the value of element 2 minus element 1. What is the least amount of code to accomplish that?

I tried this:

Code:
list<double> dList;
dList.push_back(1.0);
dList.push_back(2.0);
list<double>::iterator iter = dList.begin();
list<double>::iterator iter2 = dList.end();
double result = *iter2 - *iter;

But this code does not work. Why not?

View 6 Replies View Related

C++ :: Linked List Node Passed As Parameter / Argument Pointer To Pointer Notation

Jan 17, 2014

I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this

bool deleteNode(struct node *head, struct node *delptr)

I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.

Would also like to know why the argument call needed &head instead of just head.

remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);

#include "stdafx.h"
#include<iostream>
struct node{

[Code].....

View 1 Replies View Related

C++ :: Input Decimal Number And Output To Be Number Scientific Notation

Apr 26, 2013

I need to write a code in c++ , to input decimal number and the output to be number in Scientific notation with 32 bits .

View 1 Replies View Related







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