C/C++ :: Calculator That Uses Only Getchar / Putchar

Mar 24, 2014

I basically just have to make a calculator that only uses getchar/putchar (printf is Ok for displaying errors) - Also, negatives must be error-checked. As of right now, my program will only work if there is exactly one space between the number, operand, and other number. No spaces, or more than one space, will give me some very weird digits. I also need to display the numbers with putchar, and not printf (as I did below), but I just really wanted a working program.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
int add(int input1,char operand, int input2);
int subtract(int input1,char operand, int input2);

[Code] .....

View 12 Replies


ADVERTISEMENT

C :: Making Calculator Program Using Only Getchar And Putchar

Mar 21, 2014

I have to make a calculator program that has 5 different functions (this is obviously the easy part, once all the input is assigned to their respective variables), which are addition, subtraction, mod, multiplication and division (negatives are not allowed, and must be error-checked; spaces must be ignored). I need to take the equation from the user, echo it back and then solve the problem.

Code:

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

[Code].....

View 4 Replies View Related

C :: Swap Chars Using Getchar

Sep 23, 2014

This is for homework . Must use only getchar and putchar

Code:

int main(void) {
int pch; //first
int ch; //second

[Code]....

And it works , but i need to hit ENTER two times when i have 3,5,7... chars to print result.

View 6 Replies View Related

C :: Get Rid Of Space / Use Scanf Or Getchar

Sep 24, 2014

I want the user to be able to enter a command then a character, like for example: push r....I want the command to be stored in the array command, and the character to be stored in the variable c.

Now I wonder what the best way to get rid of the space is, using scanf or getchar (see below for code, only thing that I changed between the 2 versions is the statement before the comment "get rid of space")? Or maybe it doesnt matter?

Code:

include <stdio.h>
#define MAX 200
void push(char c); // Puts a new element last in queue
char pop(void); // Gets the first element in queue
static char s[MAX];
}

[code]....

View 6 Replies View Related

C :: Getting Integer With Only Using Getchar Function

Nov 16, 2013

I need to get an integer number with only using getchar() and without pre knowing the number of digits in the integer. And I cannot use strings or arrays.

View 4 Replies View Related

C++ :: Getchar - Return Assigned Value

Nov 9, 2012

Once again i hit a very simple problem i am unable to resolve. I using Visual Studio 2010, but am compiling for C.

This:

Code:
char i=45;
while(i=getchar() != EOF)
{

should imo work perfectly (yes, no real code, just to demonstrate the issue), but it doesnt. Getchar() always returns 0x01. Why is that? This, in contrast, works perfectly fine:

Code:
char i=45;
while(i!= EOF)
{
i=getchar();

Shouldnt an assignment always return the assigned value?

View 2 Replies View Related

C :: Getchar - Clear Input Buffer For Next Input Through Scanf

Aug 13, 2014

I would just like to know what does

while( (c =getchar())!='
' && c !=EOF );

do ? and how it do it?

I have see it in a example to clear the input buffer for next input through scanf but does not know its working clearly.

it is used in this example :

Code:
#include<stdio.h>
struct linklist {
char value[20];
struct linklist *next;
};
struct linklist *head,*curr;

[Code] .....

View 4 Replies View Related

C++ :: Write A Calculator Using Two Stacks

Apr 13, 2014

I just started by defining a stack class (stackDouble). I need to write a program that accepts an infix calculator expression, with the following operators (**, exponentiation, /, division, and, -, subtraction. The operator precedence is exponent, division, and subtraction.I need to use a stack of doubles and a stack of strings, of which I can write two classes, or write a single stack template. The user will input the expression just via cin, and there will be a # before every number, a ! before each operator, and a . at the end of the expression. '#', '!', or '.' can be input into a char variable, numbers into a double variable and operators into a string variable.

For example, the following would output 6:

# 3 ! / # 2 ! / # .5 ! ** # 2 .

As stated above, I already made up a stackDouble class. What would I need to do to create the other class (I don't think I want to do it with a template)?

Code:
#include <iostream>
#include <string>
using namespace std;
class stackDouble{

[code]....

View 2 Replies View Related

C :: BMI Calculator With Added Function

Aug 17, 2013

getting error with gcc under OSX.

Code:

/* bmi2.c */
#include <stdio.h>
main()
{
float height, weight;

printf("Enter weight:
");

[code]....

View 2 Replies View Related

C :: Calculator Using Mouse With A Bug While Dragging

Mar 6, 2015

I have an assignment to do a calculator in C, wich will work by clicking the numbers with the mouse, however i have a bug that when i hold the mouse and dragg it, it assumes that I'm clicking multiple times, also, when I click in an empty space the program creates a blank space on the calculator screen.

Code:

#include <stdio.h>
#include <conio.h>
#include <math.h>
#include "..MouseHandler.h" // ajustar o caminho ao seu projecto
#include "..calcSkinLib.h" // ajustar o caminho ao seu projecto
#define PI = 3.1415;

[code]....

View 2 Replies View Related

C++ :: Creating Exact Age Calculator?

Aug 3, 2014

I've been wondering this, since there is so many things which needs to be taken care of. I created one, but it wasn't precise.

View 19 Replies View Related

C/C++ :: GPA Calculator With Text File?

Mar 5, 2015

I'm trying to create a program that will calculate the gpa of several different students, whose data are in a text file. The file looks something like this, with possibly more lines.

Mark 3 4 A 3 D 2 C 1 A
Tom 2 3 A 2 C

The very first number tells us how many credit hour/grades will follow. I have a couple of problems though: From the code I've written I don't seem to get any data other than the first line. Also the gpa that does print out after the file runs is just a 0.00, rather than the actual gpa.

#include<stdio.h>
int main(void)
{

[Code].....

View 6 Replies View Related

C/C++ :: Error When Trying To Program BMI Calculator

Aug 26, 2014

'm trying to program a BMI calculator in C for my assignment where the weight must be in KG and an int , and the height must be in m and a double value. The program should allow the user to input his weight(kg) and height(m) separated by a space and be able to calculate and display the BMI. My code is shown below :

#include<stdio.h>
int
main(void) {
int weight;
double height,bmi;
bmi = weight / ( height * height ) ;
scanf("%d%lf" , &weight , &height );
printf("BMI = %f", bmi);
return 0;
}

However , after running the program , I constantly get a 1.#INF00 value for my result.The compiler did not show any errors so why I'm getting this value.I input my weight and height in this format "45 1.65" 45 being the weight and 1.65 being the height.

View 3 Replies View Related

C/C++ :: Area Of Triangle Calculator?

Nov 16, 2014

I was asked to build a small program to calculate the are of a Triangle but my code must have some problem.. />

#include "stdafx.h"
void main()
{
int a,b;

[Code]....

I get this errors:

-warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

-warning C4244: '=' : conversion from 'int' to 'float', possible loss of data

View 4 Replies View Related

C++ :: Calculator Using Pointer Does Not Work

Jan 18, 2015

I am making a calculator where I will input 5 array of numbers and calculate those numbers with pointers or whatever you call it. I am getting an error like

note C:Dev-Cppincludec++3.4.2itsostream.tcc:63 candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]

and more error if I try to fix the code. So yeah, can i have a hand?

Btw, here's my code.

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
using namespace std;
// function declaration:
void getAverage(int*);
void getSum(int*);

[Code] .....

View 7 Replies View Related

C/C++ :: Adding Calculations To BMI Calculator

Oct 8, 2014

I have to enhance my BMI program to tell whether the person is at optimal weight, under weight, or overweight and I cannot find the correct calculation. Here is the code I have so far that works for calculating the BMI.

namespace Body_Mass_Index {
public partial class BMI_HW : Form {
public BMI_HW() {
InitializeComponent();

[Code] ....

View 14 Replies View Related

C++ :: Make Different Type Of Calculator Out Of Boredom

Feb 10, 2014

ive been learning from the book for 4 days and decided to make a different type of calculator out of boredom but im really having problems when i try to make it a loop? ive been scratching my head trying to work it out rewriting deleting etc but cant work it out

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

[Code].....

View 9 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 :: Calculate Equations Just Like A Standard Calculator

Oct 23, 2013

The main point of the program is to calculate equations just like a standard calculator but I wanted to do it myself. I don't understand what the problem is right now but I've managed to create a program that asks for both values but somehow it doesn't want to ask for an operator (*, /, + etc). What's wrong with my code that the terminal skips the scanning part for the operator?

Code:

#include <stdio.h>
int main() {
int value1, value2, answer;
char operator;

[code]....

View 12 Replies View Related

C++ ::  Calculator Program - Function Does Not Take 0 Arguments

Jan 29, 2014

I am supposed to get 2 numbers then have the person choose what they want to do to the numbers. Here is the code:

//Mike Karbowiak
//12/24/13
//Mathematics
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>

[Code] ....

The errors I am getting so far are:

error C2660: 'Add' : function does not take 0 arguments
error C2660: 'Subtract' : function does not take 0 arguments
error C2660: 'Multiply' : function does not take 0 arguments
error C2660: 'Divide' : function does not take 0 arguments

View 3 Replies View Related

C++ :: Generic Shape Area Calculator

Dec 6, 2013

I'm building a pretty basic calculator program that calculates the area of generic shapes (triangles, rectangles, and squares); for some reason though, my program is having troubles as soon as it hits the if/else code in the int main section. When I enter triangle, rectangle, or square, it just spits back out the "That's not one of the options. Please re-enter and try again." error line I created. When I isolate and run just the stuff inside the if/else statements it works great, but why it won't just understand my if (shape == triangle).... .

Code:

#include <iostream>
using namespace std;
class figure {
protected:
double x, y;

[Code] ....

View 2 Replies View Related

C++ :: Cone Volume Calculator Program

Nov 6, 2014

I'm working on below program and I want the program to do the same thing, but with not one main() function, but instead one main() function PLUS one user defined function called computeConeVolume that contains the calculation. In other words I want to remove the one line calculation and replace it with a function call, then write and add the function below main with the calculation, surrounded any other syntax that I need to complete it.

The function should contain local variables and a constant declared and must have the calculation, it may not do anything else such as input or output. Should be able to declare "global" variables anywhere but no variables above or outside of main() and the function are allowed. A value-returning function should be used because it's a little simpler to understand, but you can employ a void function. Need to have a function prototype at the top of the code, then main, then your function.

//Cone Volume Calculator Program
#include <iostream>
using namespace std;
int main( ) {
//Declare variables and constants
double coneRadius = 0.0;
double coneHeight = 0.0;

[Code] ....

View 6 Replies View Related

C++ :: Simple Calculator - Result Will Always Equal Zero

Jan 21, 2014

I'm making a simple calculator and have done it all right where you can input everything, all the functions are there, but when i run the program it will come to displaying the result and it will always equal zero, I just need it to say 8+8 = 16 rather than 8+8 = 0, i don't know whether its just displaying the results as 0, or not displaying it at all, the code will follow below:

Code:

#include<iostream>
using namespace std;
double num3;
double num2;
double result;
char operation;

[Code] ....

View 4 Replies View Related

C++ :: Layout Design Matrix Calculator

Aug 26, 2013

I want to ask on how to put a layout design in the program when it is being ran. It should look like these: [URL] ....

This is a sample code:

#include<iostream>
using namespace std;
main() {
int m, n, c, d, first[10][10], second[10][10], sum[10][10],
minus[10][10], times[10][10];
char ans;

[Code] ....

View 2 Replies View Related

C++ :: Calculator Program - How To Do Sine Calculation

Apr 26, 2013

I am basically trying to make a program for a calculator. I am struggling with how to do the sine calculation. this calculation will take place at line 158.

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

double firstNumber = 0.0;
double secondNumber = 0.0;
char operation =' ';

[Code] ....

View 1 Replies View Related

C++ :: Bitcoin Calculator - 40 Billion In Variable

Dec 3, 2014

I'm trying to do a bitcoin calculator, however I can't get the difficulty (40007470271) to any variable

uint64_t diff = GetDlgItemInt(hWnd, IDC_DIFF, NULL, TRUE);
uint64_t speed = GetDlgItemInt(hWnd, IDC_SPEED, NULL, TRUE);
uint64_t price = GetDlgItemInt(hWnd, IDC_PRICE, NULL, TRUE);

stringstream ss;
ss << diff << " - " << speed << " - " << price;
MessageBox(hWnd, ss.str().c_str(), NULL, NULL);

diff returns 0, even when I just do GetDlgItemInt to the stringstream it's 0, how should I somehow save the variable so I can use it in calculation?

I also tried getting value as a text and then converting it to 64bit int, but I'm getting some weird number, over 300 Billion...

int len = SendMessage(GetDlgItem(hWnd, IDC_DIFF), WM_GETTEXTLENGTH, 0, 0);
string str;
GetDlgItemText(hWnd, IDC_DIFF, (char*)&str, len+1);

[Code] ....

View 15 Replies View Related







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