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


ADVERTISEMENT

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++ :: Implementation File Versus Header File - Eclipse Giving Errors

Feb 10, 2013

I have written my program and it works when I keep everything in the header files, and then have my main. I am now splitting them up into implementation files, but Eclipse keeps giving me errors. It gives me error at every opening brace of the constructor and functions. It says on all of them "Redefinition of (name of constructor or method), Previously declared here." What am I doing wrong, because it works in the header file?

#include "KeyValuePair.h"
template<typename Key,typename Value>
KeyValuePair<Key,Value>::KeyValuePair()

[Code] .....

View 3 Replies View Related

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 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 :: Original Text File / Generate Another File With Text Content In Upper Case

Nov 29, 2014

Code software that, from an original text file, generate another file with the text content in upper case.For exemple:

entrence:

luke
tom
alex

outings:

LUKE
TOM
ALEX

My code so far:

Code:

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

[code]....

View 2 Replies View Related

C/C++ :: Program That Opens Text File And Checks Usernames Listed In Text Files?

Jun 5, 2014

I want to make a program that opens a text file and checks the usernames listed in the text files to see if the names are registered on a site such as twitter. How easy would this be to make, what things would I need to know?

View 4 Replies View Related

C++ :: Getline - Get Text File And Read Only First 100 Lines Of Text Content

May 31, 2013

I am trying to get text file and read only first 100 lines of the text content using c/c++. how can i do it?

is it something like string line;
getline(stream,line);

??

View 7 Replies View Related

C++ :: Filter Text Enclosed In Specific Tags From Text File?

Aug 30, 2013

I have a huge text file in following format:

{Bunch of text
.
.
}

[Code].....

I want to extract Text1, Text2, Text3, Text4,..., Text600 in the output file. How can i achieve this?

/* BTW, I am not getting my homework done here. I am an ex-programmer, who has now moved to marketing for some time now, and today, I encountered this problem, which I believe can be solved easily through programming. */

View 3 Replies View Related

C/C++ :: Delete Text From File And Than Shift The Rest Of The Text Upward

Aug 31, 2014

i want to create 100 gmail accounts instantaneously....what i want from you guys is i have written a program that create a text file i want that once i give the program the imput of 1 it should delete the first 3 lines from the file i.e. the first account details coz that is already been created and shift the rest of it 3 lines upwards after that i'll write a javascript that will automatically fill and create the accounts with those names in web browser.....my lil program is here:

#‎include <stdio.h>
#include <conio.h>
main()

[Code]....

View 1 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++ :: Giving Score To Correct Player

Jul 22, 2013

I have programmed a game where you guess a number (1-6) and if the number is equal to the random number then give the player score + 10. But if I have selected for example 4 players then if the game will give player 1 a score it gives player 2 a score instead? What can be causing this error?

Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int cube;
int number[4];

[Code] .....

View 6 Replies View Related

C++ :: Giving Audio Input To A Program

Sep 27, 2013

I want to give audio-input to a FFT code (KissFFT) written in C, on a real-time basis. While I can give a simple test signal (like sine wave) by writing the sine function as input, I am not sure how I should convert an audio-signal (e.g.: song) into a form that can be taken as input by the KissFFT C code.

View 3 Replies View Related

C++ :: Array / Pointer Giving Error?

Jul 20, 2013

The program should ask the user how many students were surveyed and dynamically allocate an array of that size. The program should then allow the user to enter the number of movies each student has seen.

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

[Code].....

The problem I'm having is that where I declare movies = [numStudents]; the semicolon after the numStudents array is giving me this error - "error: expected a '{' introducing a lambda body".

View 2 Replies View Related

C# :: Random Numbers Giving Same Number

Jul 30, 2014

Not a major issue since I got this to work but for some reason both my random numbers are the same and not sure why ...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class ComputerAssistedInstructions {
private static Random rand1 = new Random();
private static Random rand2 = new Random();

[Code] .....

View 2 Replies View Related

Visual C++ :: Giving Values To All The Members?

Oct 15, 2013

Write a C++ program to implement the following description:

1. Define a global structure and name it GStruct with the following members:
a. X as integer
b. Y as integer.

2. Define a local structure inside the main and name it LStruct with the following members:
a. X as integer
b. Y[3] as GStruct

3. Inside the main declare two variables V1 and V2 of type LStruct.

4. Give values to all of their members by using input statement (cin).

5. If V1 equal V2 print "They are equal" else print "Not Equal".

#include <iostream>
using namespace std;
struct GStruct {
int x;
int y;
};
int main() {

[Code] .....

View 1 Replies View Related

C++ :: Extracting Specific Lines Of Text From A Text File

Aug 2, 2014

I have a text file called (Test.txt) with the following text:

This is line one
This is line two
This is line three

How do I go about writing a program that will print a line of text (e.g. "This in line two" on the console screen?

All I can seem to do is display the entire text file.

View 6 Replies View Related

C++ :: Dividing Two Floats Not Giving The Required Quotient

Jan 9, 2014

Im using the remquo function in the cmath library as follows:

int quotient;
double a = remquo (10.3, 4.5, "ient);

This gives the correct remainder (a = 1.3) and quotient (quotient = 2).

Infact about 50% of the answers are right when I play around, however, trying something like:

int quotient;
double a = remquo (2.25, 1.5, "ient);

yields an incorrect quotient of 2 and remainder of 0.

I do think this has something to do with float arithmetic. I recall tinkering with the float number 0.500 and that the CPU actually saves it as 0.50000000000000231. However if my suspicion of float arithmetic as the suspect is correct, I do not understand why a tenth decimal would make such a drastic difference as changing the quotient result.

View 10 Replies View Related

C++ :: Code Blocks No Longer Giving Any Useful Errors

Jun 8, 2013

I'm using Code:Blocks 12.11 on windows 7, with the built-in MinGW compiler. When I try and compile a program that has an error in it (misnamed variable, missing include, extra semi-colon somewhere, anything) instead of saying something about what went wrong it just has this:

Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)

Which is not particularly useful for debugging.

View 11 Replies View Related

C++ :: Using Same Socket For Second Send / Receive Giving No Result?

Jul 28, 2013

when I want to use the same socket connected to the host to send() and recv() for the second time, recv() will return 0 without anything in buffer. Basically I am doing:

1. connect to the website
2. send packets
3. receive packets
4. send packets again (I think this one is working since it's not giving me SOCKET_ERROR)
5. receive packets again (this one is returning 0 so as "connection closed")

source code: [URL] ....

as you can see, I have sock2, which when I use for second send/recv it's working fine, however I will do more communication, and having sockets for all of that and connecting them.

View 4 Replies View Related

C :: Retrieve Information From A Website - Libcurl Not Giving Output

Apr 2, 2014

I am trying to retrieve information from a website [URL] .... and have written a C code as follows:

Code:
#include <stdlib.h>#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
int main(int argc, char* argv[]) {
/* Exit status to return */
int exitStatus = 0;

[Code] .....

The output of this program should be:
From To
4504111 B0LPF3
4504111 P62993

The first print option [printf("%s", url)] gives the url output as [URL] .... which on being manually pasted in any web-browser gives the correct output but the program fails to give the output.

View 1 Replies View Related

C++ :: Game Control - Organizational System Giving Errors

Jun 24, 2014

I'm making a game with the following class structure:

GameControl - The class that actually runs the game, with a while(!closed) // run the game loop.

State - A class that handles the state of the game, for example if the game is rendering the scene it would be in one state, and if it is rendering the menu, it would be in another.

ComponentManager - A class that manages all of the components of what is being done, for instance, the Scene class would contain a bunch of components handling the drawing of each tree, physics, the camera, etc. The manager will put them all together.

Component - A component of whatever is being done. A tree (and its rendering code) would be an example of a component of the scene. The camera would be another. The component does not necessarily have to be drawn, it could be handling something like physics (and would throw physics events to other components that need to move in a certain way).

The GameControl class has its loop, which would call the update function on the current State (there are classes that inherit State and override the update function of State).

In the update function of the base class "State", it would take all of the active ComponentManagers and update them. There are classes that inherit the base class ComponentManager and override its update function.

Each ComponentManager would update each of the Components that it owns.

This is the organizational structure that I came up with to make the game scalable and changeable . If, for instance, I wanted to add multiplayer at some point, I would add a class that inherits the State that controls the gameplay called "MultiplayerGameState". This would just add a new ComponentManager that inherits the ComponentManager that controls the player and all of the living things that are moving around. Then, the MultiplayerGameState class would recieve the multiplayer messages coming in and add other player Components for the other players.

My code is giving me various errors like "Forward definition of class State" and "Invalid use of incomplete type State". Unless I made some stupid error that I didn't catch, these are being caused by me including the classes in ways that some of the classes do not see the full definitions of the classes they need to see (because of the preprocessor directives preventing classes from being included multiple times.

Code: (Not implemented exactly as shown above, but I think the main difference is that the main class is not in GameControl, it's in OgreFramework.cpp)

The base classes: [URL] ...
States: [URL] ...
ComponentManagers: [URL] ...
Components: [URL] ...
The project: [URL] ...

My question is: is there a better way to implement my organizational system so that these errors don't occur?

View 1 Replies View Related

C++ :: Sum Of Diagonals Of Matrix - Program Giving Segmentation Error?

Jan 7, 2015

After entering the values of the matrix, it is giving me segmentation error. also "if possible", correct it

#include<iostream>
using namespace std;
int main()
{

[Code]......

View 2 Replies View Related

C++ :: Merge Sort Implementation Giving Incorrect Output

Oct 25, 2014

I've implemented the merge sort algorithm and used the 'merge' part for counting the number of split-inversions in an array as part of an assignment for an online course. How ever, the out put array is not a sorted version of the input array and as a result the number of split inversions obtained is wrong. I think that there is some thing wrong in the way I am indexing arrays.

I've used ' cout ' to print the values of indexes to see exactly what values are being passed in during the recursions.

Code:

#include <iostream>
using namespace std;
int length=0,mid=0,inv=0;
void mergesort(int arr[], int first, int last) {
cout << "first: " << first << " " << "last: " << last;
cout << endl;

[code].....

View 5 Replies View Related

C++ :: Program To Find Quarks And Their Charge And Mass - Giving Error

Mar 3, 2013

I have been looking and i'm stuck on this. I wrote this program to find quarks and their charge and mass but i need it to give me 5 different ones. so i made an array but when i run it it gives me this

"Unhandled exception at 0x001631c6 in DiasQuarkP1V0.exe: 0xC0000005: Access violation reading location 0xd5bf0c38." and it shows the xstring library.

this is my main, is their anything wrong with my code?

#include "StdAfx.h"
#include <stdio.h>
#include <string>
using namespace std;
int main() {
Quark solution[5]={};

[Code] .....

View 1 Replies View Related







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