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


ADVERTISEMENT

C :: Addition And Subtraction Calculator That Takes Input?

Feb 23, 2013

I'm writing an addition and subtraction calculator that takes input as: 5+6-3+2. You should be able to add or sub as many numbers as you want. I want the while loop to stop when the user hits enter. I put the getchar() function to catch the and break the loop but it is also swallowing the '-' sign, which I want to use to subtract and is instead adding the numbers with "sum+=number". How can I get around that?

Code:

#include <stdio.h>
int main(int argc, char *argv[]){
int number, sum = 0;

[Code]....

View 3 Replies View Related

C++ :: How To Allow User To Input Operator Into Calculator Function

Aug 24, 2014

How I can let the user input a certain operator into this calculator function?. I would like to use cin to input the operator if possible because it is one of the only input commands I know.

// Calculator.cpp : Defines the entry point for the console application.
// Calculates the value of two numbers based on the four main operations.

#include "stdafx.h"
#include <iostream>
int add(int x, int y);
int subtract(int x, int y);
int multiply(int x, int y);
int divide(int x, int y);

[Code] ....

View 1 Replies View Related

C++ :: Federal Tax Calculator Based On User Input

Apr 17, 2014

I am doing an assignment that is to calculate the federal tax based on the users input. I am not entirely sure what it is doing, but it is definitely not what I want it to do. I commented out the loops because they seemed to have caused a problem, but there is still problems that are making the program do something else. Here is my code:

#include<iostream>
#include<string>
using namespace std;
double getData();
double taxAmount();

[Code] ....

Functions just seem like they are not my thing. It never gets to the second function to do the calculations and then return to main to display the results.

I tried changing the code to a switch(status) with a default: at the end that looped the "please try again" but for some reason, that was a fail, it created an endless loop.

View 15 Replies View Related

C/C++ :: Calculator With Differing Number Of Variables

Jan 31, 2015

I'm working on an assignment where the user inputs the center coordinates(x,y) for an circular array of (x,y) points. The program performs some calculations, then outputs the position of each point, based on the diameter and center location.

The issue I'm having is that the number of points is a variable(inputted by the user). How to make the program perform the calculations for a different number of points each time.

Code:

// Bolt position Calculator
// Calculates position of bolts on plate using number of points, hole diameter, and (x,y) coordinate of center

#include<iostream>;
#include<math.h>;
#include<cmath>;
#define PI 3.14159
using namespace std;
int main() {
int n,xn,yn
float D,x,y,A;

[Code] ......

View 2 Replies View Related

C/C++ :: Simple Calculator - Clear Screen Following User Input

Dec 10, 2014

I am working on a simple calculator in C++ .... All works fine with the calculator up until the requirement for the user to input "do you want to go again y/n" .... What i want to happen is the screen to clear down and reloop to the enter name part....but i can't get it to do that

Program Description: To write and develop a programme where a user can input a cost or price of something before VAT our program must then process the input number and must output the price with the original value plus VAT

#include <iostream>// I must use this to start my programming
#include <string> // I have added this for the extension task so the user has to input their name
#include <iomanip> // this is to manipulate the text
#include <stdlib.h>
using namespace std; // using the "using namespace std" shows that i will be using standard text throughout this programme

[Code] .....

View 5 Replies View Related

C# :: Sending Input To Specific Window

Feb 18, 2014

I have some experience in C# and choose the project of a "rapidfire script". It is a program, which shoot rapidly in a FPS by sending a "left-mouse-button-click" over and over again while the "real" left mouse-button is down.

Now, I tried multiple ways of sending the left mouse button but none of them worked the way I wanted them to. I tried SendMessage, PostMessage and mouse_event. One of them made the window unresponsive, another only pressed the mouse button while I was still moving the mouse and another didn't work at all.

I know a script which does exactly that and is coded in AutoHotKey. AHK is open-source but since I am not familiar with C++, it is very hard for me to understand what exactly is going on here:

AutoHotKey: keyboard_mouse.cpp

And here is the AutoHotkey-Script: AutoHotKey - pastebin.com

And my current code. The input delay is very irregular and strange. Sometimes the real "right mouse button click" gets ignored and I don't know why.

if (State == RapidfireState.ACTIVE) {
// Check if the left mouse button is down. If it is, send fire commands to the game
if (MouseDown()) {

[Code]....

View 2 Replies View Related

C++ :: Basic Calculator - User Will Have To Press Enter After Every Number

Mar 22, 2013

I'm stuck because I can make the calculator just find but the user will have to press enter after every number, what is s solution to this?

#include <iostream>
#include <string>
using namespace std;
int a = 1, b, c;
string symbol;
int multiplyFunction();

[Code] .....

View 6 Replies View Related

C :: How To Input Lines At A Specific Area In File

Feb 15, 2013

how can i input lines at a specific area in my file. please provide code

View 3 Replies View Related

C++ :: Saving Specific Bits From 64-bit Number

Jun 24, 2013

I have a 64-bit uint64_t number:

Code:
Primitive<uint64_t> b = 0xCCCCCCCC00000000; I need to save the first 31 (most important) bits - 7FFFFFFE.

I found this solution in the Internet:

Code:
start = (((b)>>(first)) & ((1<<(((last+1)-(first))))-1)); but in my case for this code:
Code: Primitive<uint64_t> start = (((b)>>(32)) & ((1<<(((63+1)-(32))))-1));

I get an error: left shift count >= width of type

And even if I change 63 to 62:

Code:
Primitive<uint64_t> start = (((b)>>(32)) & ((1<<(((62+1)-(32))))-1));

I get: error: integer overflow in expression

View 5 Replies View Related

C# :: Creating Complex Number Calculator - Convert String To Ints

Sep 18, 2012

I am working on an assignment to create a Complex number calculator. In this assignment I am to ask the user for input to the calculator. We are given a sample run output that looks like this.

Enter operand1: 3 4
operand1: (3, 4)
Enter operation : +
Enter operand2: 1 2
(3, 4) + (1, 2) = (4, 6)

My question is how would I take from the user: an integer followed by a space followed by another integer and convert that into two seperate accessible int values that I can save as real and imaginary values.

View 4 Replies View Related

C++ :: Reading Specific Input Syntax - String Parsing

Apr 21, 2013

I need reading a specific input syntax.

something like

<Input> :: R C <Content>

3
3

.3. .15 9.2
.1. ..6 ...
6.5 7.. ...

... .5. ..9
4.7 .8. 1.6
9.. .6. ...

... ..1 7.4
... 6.. .9.
5.1 49. .3.

View 2 Replies View Related

C++ :: Looping User Input For Specific Data Type

Apr 17, 2015

Here's my code so far:

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int dayNumber = 1;

[Code] ....

The code, when run, prompts the user to input an integer like this:

Code:

Day 1
Andy :>12
Bill :>7
Charlie :>15

Day 2
Andy :>5
Bill :>25
Charlie :>14
.
.
.
etc.

Ok, so the code prompts the user to enter an integer for each of the 3 persons and then increments the "Day" and so on... When the user enters a negative value (-1, -2, etc.), the loop is broken and the program ends. Alright, everything is hunky-dory so far. 2 things which I can't figure out.

1. when the user doesn't enter anything and just hits return, the cursor drops a line and is still awaiting an input but doesn't show the prompt "Andy :>", for example. How can I get it to repeat the last prompt when the user doesn't enter anything? Like:

Code:

Day 1
Andy :>
Andy :>
Andy :>12
Bill :>25
Charlie :>15
.
.
etc.

2. When the user enters a letter or a special character, the program blows up. How can I correct this?

I've tried changing the data type for the variable used for the input, tried using getline, get, etc. With my current beginner knowledge, I'm missing something. So how can I get this to work?

The program should allow only integers to be entered, while allowing a negative number to trigger the loop to break or the program to end, and while re-prompting the last person if the user entered an invalid input.

View 13 Replies View Related

C++ :: Create A Specific Number Of For Loops Each In Another Loop

Sep 18, 2014

I want to create a specific number of for loops each in another loop, as in example:

for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
for(k=0;k<9;k++)
{
//some stuff
}
}
}

In this example there are 3 loops, but what if i want to create e.g. 10 such loops, and program reads a number of loops from a txt? It is needed for checking numbers.

View 2 Replies View Related

C/C++ :: Counting Specific Amount Of Times A Number Shows Up

Apr 11, 2015

Ok, so I am writing this program with 10 different functions, and one of those functions needs to count how many times 0 appears in a text file. I've done this before, but I am so stumped right now. Should I get the numbers from the 2d array I have, or should I just use the text file here? Here is what I have right now:

int toursMissed(int scores[][COLS]){
int counter;
for(counter=0;counter<=96;counter++){
if(scores==0){
counter++;
return counter;
}
}

View 7 Replies View Related

C Sharp :: Assign A Specific Number To Each Letter In A Sentence?

Feb 14, 2014

I have a string - a whole sentence that I want to assign a number to each letter, space, comma and period etc. So all "A's" will have the same number, all "B's" will have another number etc. I don't want to use the ASCII numbers because they all need to be sequential and some of the punctuation isn't. I have put the string into a char array to separate each character out and was thinking about running it through a loop with if statements for each letter and assigning numbers there and then saving the numbers in the order they appear into a list as a string but I keep coming up with errors so I don't know how to do it or if there is a better way to accomplish what I'm trying to do.

View 1 Replies View Related

C/C++ :: How To Ask A User To Enter Date And ISBN Number In Specific Format

Dec 4, 2014

I don't know how to ask the user to enter the date in this format (DD/MM/YY) and ISBN number with hyphens.

After user enter date and ISBN number, it should look like this:

Date: 5/24/12
ISBN: 0-000-12345-0
#include <iostream>
#include <string>
using namespace std;
int main() {
string date;//MM/DD/YY Format

[Code] ....

View 7 Replies View Related

C++ :: Determine Number Of Times Change Each Specific Character In String To Make It Palindrome

Feb 19, 2015

I'm trying to determine the number of times I have to change each specific character in a string to make it a palindrome. You can only change a character one at a time from the end.

Example: "abc" -> "abb" -> "aba" should print 2. "aba" will print 0 because it's already a palindrome. "abcd" -> "abcc" -> "abcb" -> "abca" -> "abba" will print 4 because it took 4 changes to make a palindrome.

I'm not too sure how to approach this - I figured out the case where if it's a palindrome (if reversed string is the same) then it'll print out a 0.

int main() {
int number;
cin >> number; //expecting a number for first line user input
for (int i = 0; i < number; i++) {
string str;

[Code] ....

View 1 Replies View Related

C++ :: How To Make Specific Character Show Up Specific Amount Of Times

Mar 5, 2013

How do I make a specific character show up a specific amount of times?

Like I am generating a random number then I need to make "|" show up that many times on the screen.

View 1 Replies View Related

C++ :: How To Read Input Of Arbitrary Amount Of Numbers Instead Of Specific Amount

Feb 25, 2015

I'm trying to make a program that allows the user to input an arbitrary amount of numbers and finding the largest of all the inputs but I keep having problems with the output.

javascript:tx('
#include <iostream>
using namespace std;
//******************************************
//CLASS COMPARATOR
//******************************************

class comparator {
public:
comparator();

[Code] .....

And regardless of what numbers I enter, I always get the output of 10. Also I got the EOF idea from my textbook so if there is a better way of doing this I'd like to hear it. I don't know any clear ways that looks nice to end the while loop when the user doesn't have any more numbers to enter.

View 3 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

C++ :: Find Next Palindrome Number Larger Than Input Number

Nov 14, 2014

Q. WAP to find the next palindrome number larger than the input number.

for eg:-

Input=25
Output=33

The program is giving correct output for number with all digits '9';

why is it not giving output.

#include<iostream>
#include<string>
using namespace std;
int main() {
int len,flag=1,count=0,num,ind;

[code]....

View 8 Replies View Related

C :: Asks To Input Number Nad If Outside Number Asks To Put In Number Within Bounds

Mar 23, 2013

I have to write a program that will ask you to put in a number between 0 and 9 and multiply it by pi. If the number put in is between 0 and 9 then pi is multiplied but if it isnt between 0 or 9, it will say the number is not between 0 and 9 and asks you to put it in again and will repeat until a number between 0 and 9 is put in.

I have got the program working to the extent that it the number is between 0 and 9 it will multiply it by pi but if its not between 0 and 9 it will say the number is not between 0 and 9 and ask to put in a new number.

I can't work out how to get the program to repeat itself if the number entered isnt between 0 and 9.

I have enclosed the code below .....

View 5 Replies View Related

C/C++ :: How To Mix Each Number Given By User Input

Jun 29, 2014

There's this program I'm trying to code where the user gives input of 2 values.

Sample :-

Value of X: 1234
Value of Y: 234567
Reversed value X: 4321
Reversed value of Y: 765432
New value as Z: 1223344567 (each number was taken in both X and Y)

Now the thing is I could do the reverse, and I've been trying to find out how.

Here's my code,

#include <iostream>
using namespace std;
int main(){
int x=0, y=0;
int reverse_x=0;
int reverse_y=0;
int z = 0;
int l;

[Code]....

What I thought about that area where I've put a comment on, I was wondering if I code a loop for the amount of times x gets divided by 10 until it becomes 0 and store it in the value, same thing for Y, and add the value together to get Z. But if that's how it is then how I could use that concept here.

View 5 Replies View Related

C++ :: How To Take Binary Number As Input

May 31, 2013

how to take binary number as an input, generate partial products by bit-wise multiplication and in last step to add all the partial products to generate final products".

View 5 Replies View Related

C/C++ :: How To Mix Each Number Given By The User Input

Jun 29, 2014

There's this program I'm trying to code where the user gives input of 2 values.

Sample :-
Value of X: 1234
Value of Y: 234567
Reversed value X: 4321
Reversed value of Y: 765432
New value as Z: 1223344567 (each number was taken in both X and Y)
Now the thing is I could do the reverse, and I've been trying to find out how.

Here's my code,

#include <iostream>
using namespace std;
int main(){
int x=0, y=0;
int reverse_x=0;
int reverse_y=0;
int z = 0;
int l;

[Code]...

What I thought about that area where I've put a comment on, I was wondering if I code a loop for the amount of times x gets divided by 10 until it becomes 0 and store it in the value, same thing for Y, and add the value together to get Z. But if that's how it is I can't seem to really get that idea how I could use that concept here. I'm not really good with programming, fairly new at this.

View 1 Replies View Related







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