C++ :: Simulate Adding Machine - Total / Subtotal

Mar 28, 2013

Write a program that simulates an adding machine. When a zero is entered it should print the subtotal of all the numbers entered from the last zero that was entered and reset the subtotal. When two consecutive zeroes are entered it should print the total (not the subtotal) of all the numbers entered and terminate the program. Example:

1
2
3
0
subtotal 6
4
5
-2
0
subtotal 7
8
0
subtotal 8
0
total 21

Be careful this program needs a bit more thought than you might think at first. To get full credit you must make sure it also works for the 0 - 0 case. Example:

0
subtotal 0
0
total 0

The problem is, after I enter the integers and type 0, it shows the subtotal which is what I want; however, when I type more integers and type another 0 to see the subtotal again, it shows the total instead. The subtotal should reset whenever a single 0 is typed and the total should only show when two 0's are inputted simultaneously. Also, after the user enters two 0's simultaneously and views their total, I want the program to exit by saying "press any key to exit." Is there a special name for that to happen? Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
int subtotal = 0, total = 0, number = 0;
bool input_zero = false;

[Code] ....

View 2 Replies


ADVERTISEMENT

C++ :: Total Is Not Adding Up?

Jan 14, 2015

Every time I run if(color=="1") it's supposed to add 1 to redTotal. However, every time I run if(color=="1") if get 1 for redTotal every time.

(Write a program that provides the option of tallying up the results of a poll with 3 possible values. The first input to the program is the poll question; the next three inputs are the possible answers. The first answer is indicated by 1, the second by 2, the third by 3. The answers are tallied until a 0 is entered. The program should then show the results of the poll—try making a bar graph that shows the results properly scaled to fit on your screen no matter how many results were entered.)

Code:
#include <iostream>
#include <string>
using namespace std;
int main()

[Code]....

View 4 Replies View Related

C++ :: Adding Total Cins Entered?

Sep 30, 2013

If I entered multiple cin say for variable x, how do I total them all up at the end?

Example: x being the variable.

cin 45
cin 50
cin 22

The total would be 117 but how would I write that in c++?.

View 3 Replies View Related

C# :: Adding Value Of Columns Digits To Get Total With ListView

Oct 28, 2014

i have a list view, which is shown below as an example, i am hoping to achieve to find out a method of adding up the values in the Sub2 Column in C#. Then i will output it to a label on my form. So the total should be 14. But i don't have a pre-defined number of rows, and thats what i needs to be. I thought of something like

label1.Text = ListView1.SubItem2.text

But no such luck....

Index Item Sub1 Sub2
-------------------------------------------
0 IE Micro 8.0
1 FF Mozil 3.0
2 Safari Apple 3.0

View 14 Replies View Related

C :: Array Add Total Rows And Total Columns

Apr 16, 2013

Code: i am trying to display the information in the array as a table and add the total rows and the total colums separately

#include<stdio.h>
int main(void)
{
int row, col;

[Code].....

View 1 Replies View Related

C++ :: COM Exe Not Running On A Particular Machine?

Jul 23, 2012

I have a COM exe which runs fine on all machines that I have used except one. On a particular machine, the COM exe does not start even after trying to execute it manually (do a double click on the file from explorer).

There are no error messages as well. what could be happening ?

View 8 Replies View Related

C++ :: Design A Program For A Machine?

Jul 10, 2014

My need is that i need to design a program for a machine. The machine takes "x"qty of load, refines 30% of it and sends back the 70% to the initial position. after how many times, does the qty of the load refined will be equal to the initial load and how many times does it need tot be refined?

View 1 Replies View Related

C++ :: Compilation In Machine Language

Jan 25, 2013

Have a program which given a C source code file, gives back RAW MACHINE CODE, which means it doesn't have to be a executable on his own.

Like:

Given a example function for C:

int stdcall Function(void)
{
return 0;
}

Gives back the Machine Code for the Example Function.

It doesn't need to be actual C code, it can also be like:

type int
return 0

Or also it can be a straight assembly-to-machine-code compiler.

Is there any Library? Or even a external tool I can look into?

View 4 Replies View Related

C++ :: Chocolate Vending Machine

Sep 25, 2013

My group's chocolate vending machine code is clean, but has a problem.

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
// Variables from function "chocoSelect".

[Code] ....

The functions doesn't seem to link in proper. Also, for the "chocoSelect" function, if a user enters a selection number other than 1 to 5, the machine will stall and wait for 10 seconds to try again. How?

View 11 Replies View Related

C++ :: Making A Finite State Machine For Lab?

Apr 20, 2013

I am making a finite state machine for a lab. I have here a 2 files with the code for the FSM. I know it isn't finished yet, I know what needs to be put in. The only things I would need help on are the errors that I get.

Warrior.h
#ifndef _WARRIOR_
#define _WARRIOR_
#include "State.h"

[Code]....

View 1 Replies View Related

C++ :: Vending Machine - Expected Primary Expression Before Else

Apr 23, 2014

This is my code so far and in my else if statements its sayin "Expected Primary Expression Before "Else"

What do i do?

#include <iostream>
using namespace std;
int main () {
//declare variable
double n,a,b,c,d,total;

[Code] ....

View 3 Replies View Related

C/C++ :: ATM Machine - Get Amount Balance Into Other Functions From File

Oct 25, 2014

I have part of it done but im not sure how to get my amount balance to get into my other functions from my file...

#include<iostream>
#include<fstream>
using namespace std;
void welcomeUser();
bool readFile();
void menu();

[Code] ....

and the amount saved that I have in the file is 1200

View 14 Replies View Related

Visual C++ :: How To Extract Machine / Hardware ID And OS Version

Nov 19, 2014

Is there a way I can extract Machine / Hardware ID and OS Version using VC++?

View 3 Replies View Related

C/C++ :: Circular Buffer In The Form Of Finite State Machine

Dec 11, 2014

I'm supposed to create a circular buffer that reads an input file and outputs data after running though basically an integral equation. Everything my be referenced by pointers. When I build I am being told segmentation fault: 11. From what I have gathered that means there is a problem with my memory allocation correct? I'm including the custom header file and the main.c as well.

header file :

#ifndef FSM_H
#defineFSM_H
#define INPUT_BUFFER_LENGTH 2
#define OUTPUT_BUFFER_LENGTH 2
#define INITIAL_INPUT {0,0}
#define INITIAL_OUTPUT {0,0}

[Code] .....

View 1 Replies View Related

C# :: Bingo Calling Machine / Changing Numbers To Different Text Boxes?

Dec 28, 2014

I've recently started creating a bingo caller application. I need in changing numbers to different text boxes. When a number is called it will be displayed in a text box and the last four numbers previous to that. However the oldest number needs to delete and for the remening numbers to move when a new number is called.

View 2 Replies View Related

C Sharp :: Store Values In Variable Permanently Even After Restarting Machine?

Dec 26, 2013

I want to store values permanently in a variable. The same variable should be able to be edited and saved by user, and whatever it is I need the value of the variable from the last time I modified it, like a database. database because i need this to set my connection string of the database.

View 1 Replies View Related

C :: UDP Application Simulate Packet Loss

Aug 12, 2014

have udp server-client application written in C. On the client side packet loss is detected using recvfrom function and sequence numbers of packets. How can I now simulate dropped packet's on the client side, for example if server is sending 1000 packet I want to drop 20% of them? I want to do this in the code, not for example using ip tables or WANEM or something like that. And one more thing, I have few clients and I want that they can dropped different packets, not the same one.

Code:
while(1){
nbytes = recvfrom(socket, buffer, MAX_SIZE, 0, (struct sockaddr *) &srv_addr, &addrlen);
if (nbytes != -1) {
// packet is received

}else{
//packet is not received
}
}

View 2 Replies View Related

C++ :: Simulate Random Walk In 2 Dimensions

Jan 6, 2015

I am writing a piece of code that simulates a random walk in 2 dimensions (an object chooses whether to move up, down, left or right randomly). I would like the program to run the simulation for many objects at the same time. The way i have written it means that for every object i add the code becomes about 40 lines longer. Any method that would simplify the code so that i could have many objects but not pages and pages of code.

#include <ctime>
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>

using namespace std;
double dist(int a, int b);

[Code] .....

View 5 Replies View Related

C++ :: Program To Simulate Coin Toss

Nov 14, 2013

Write a program that simulates coin tossing. For each toss of the coin, the program should print Heads or Tails. Let the program toss the coin 100 times and count the number of times each side of the coin appears. Print the results. The program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads. [Note: If the program realistically simulates the coin tossing, then each side of the coin should appear approximately half the time.]

View 7 Replies View Related

C++ :: How To Simulate File Space Allocation

Mar 29, 2014

I want to write a c++ code that due the structure of file space allocation,Simulates file system with 2*n array. Each column represents a sector. The first row is for storing files And second row holds the address of the next sector (Number of columns). And With each click on keyboard Create a file with random size and automatically find Appropriate sectors by using disk allocation method (or index allocation)... Also File names should be asked from user... And we should have file table Where the starting address of each sector,file extension and file size is given..

View 1 Replies View Related

C++ :: Implementing Class To Simulate A Disk

Oct 1, 2013

So this code compiles without any problem but it is not producing the correct output. I know there's a problem in either my getBlock or putBlock functions but I can't see it.

Currently the output is "Should be 32 1s: "
"Should be 32 2s: "

There should be 32 1s and 32 2s and nothing is coming out.

#include <iostream>
#include <fstream>
using namespace std;
class Sdisk {
public :
Sdisk(string diskname);

[Code] .....

View 3 Replies View Related

C++ :: Get Live Data To Simulate Algorithm?

Apr 9, 2014

How to get live streaming of stock data from yahoo finance? Using C++. I need the code and fetch the data so I can do calculations on the price and volume or what not.

View 1 Replies View Related

C/C++ :: Can Use Packed Structure To Simulate Memory?

Oct 11, 2013

I am trying to simulate memory in C. I want to create a structure in C that will hold a 8bit opcode and a 32bit memory address. This would simulate a 40 bit instruction for my simulator.

I read in an old book that packed structs could be used for this to not waste space. What are the draw backs for using this? I am not worried about wasting space, but just looking for a simple way to access the memory instructions. Below is a sample of the structure that I want to use.

struct memory_area {
unsigned int opcode:8;
unsigned int address:32;
};

View 2 Replies View Related

C :: Simulate Process Of Placing CDs In CD Container Using QUEUE

Sep 16, 2014

I'm in need of the C program which will simulate the process of placing and removing CD's in CD container using QUEUE.

View 4 Replies View Related

C :: Simulate Roll Of A Dice - How To Use Rand Function

Sep 23, 2014

I saw a program in which it uses rand like this:-

d1=rand() % 6+ 1;

where, d1 is any integer. The program is to simulate the roll of a dice. The whole program is this:-

Code:

#include<stdio.h>
#include<stdlib.h>
main() {
int i;
int d1, d2;
int a[13];

[Code] .....

View 10 Replies View Related

C++ ::  random Number Generator To Simulate A Critical Hit

Oct 25, 2013

I am trying to make a random number generator to simulate a critical hit if the number generated is from 0-critical amount. However, every time i run the code, despite being within the parameters set by the if statements, it always runs through as a critical hit and never a regular hit.

#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
srand((unsigned)time(0));

[Code]...

There are four attempts to save time in getting a good result.

View 6 Replies View Related







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