C++ :: How To Subtract A Set Value From Each Character In Array

Mar 16, 2013

this function subtracts a given value for each element in an array. I If the array is: hellohowareyou, and the value is 6 then result will be : 6 characters from each letter in the initial array

and the prototype of it is:

void minusFromArray(char arr[], int size, int value);

how do i convert each element in the array into ascii and subtract the values from those ascii characters?

View 1 Replies


ADVERTISEMENT

C++ :: Function That Subtract Value From Each Character In Array

Mar 17, 2013

I have to write a function Subtracts val from each character in the array

// If the array is: abcdefghi and value = 5, then result is: 5 ascii characters subtracted from the given array
// note: Make sure the character remains in the ' '
// to '~' (inclusive)
// If character < ' ', then add 95
// If character > 126, then subtract 95
// to put back within the range, and repeat as needed
// all printable characters are between this range
// ' ' is the 1st printable character (32)
// '~' is the last printable character (126)
note: subtracting values from the char will cause an overflow.

the prototype is: void subtracting(char array[], int size, int value)

View 3 Replies View Related

C :: Assignment Of Element Of 2D Character Array To 1D Character Array

Jul 4, 2014

Can we do this :

Code:
char strings[][100]={"ABC","EFG","IJK","LKM"};
char temp[100];
temp=strings[1];

View 3 Replies View Related

C :: How To Subtract Evenly

Feb 20, 2015

how do I subtract this so that I use the smallest number of $20, $10, $5, and $1 to pay $93? The book tells me to "Divide the amount by 20 to determine the number of $20 bills needed, and then reduce the amount by the total value of the $20 bills. Repeat this for the other bill sizes."I think the part in bold throws me off. What IS the total value of the $20 bills if I use $93 as the example? Is it $80, the highest we can go with $20 bills? Is it 4, the number I got from 93/20 after cutting off the decimal places, also the total number of $20 bills I can use?

I know how to do it and can do it in real life. It's like, "Oh, I need to pay $93. So I use four $20 bills, which brings me to $80. Using one more would bring it to $100, which is too much. So now, I need to use a $10 bill, which brings it to $90. Oh, so now, I need to use three $1 bills, which brings me to $93."But how do I tell that to a computer? It seems like I would have to put some kind of limits on it, or string code lines together,Here is the code so far:

Code:

#include <stdio.h>int main(void)
{
int amount, twenty, ten, five, one;
printf ("Enter a dollar amount:
");
scanf ("%d", &amount);
}

[code]....

View 5 Replies View Related

C :: Subtract Two Time Intervals?

Mar 12, 2014

I am looking for simple code that subtract two time interval. I have time t1=5hour 30 minute and other time in 24 hour format. This code i written but it not working as expected. it not printing 5:30 minute subtract

Code:
main() {
intTime1;
intTime2;
int hour=10;
int minute=5;
int second=13;
int h;int m;
doubleNtime;

[Code] ....

View 3 Replies View Related

C++ :: Subtract In A String With Decrementation

Nov 24, 2013

Here's my code :

>>>>>
std::vector<std::string> x = split("3 5", ' ');
int total = 0;
// then we loop over the elements
for(size_t i = 0; i < x.size(); ++i) {
// convert the string to an integer
int n = atoi(x[i].c_str());
total = total + n;
}
std::cout << "total = " << total << std::endl;
}
<<<<<

So, as you can see, this will add 3 to 5. However, I would like it to do the inverse (3 - 5). How I can do that?

View 2 Replies View Related

C/C++ :: How To Subtract Two String Containing Numbers

Mar 29, 2014

I have a code for subtract of two char arrays(size of each is 50).but i want to write this program with string and i should be consider that size of each string may be not equals.for example we have s1=4777 and s2=55.and we should be subtract them. This is my code.

char* sub(char x[50],char y[50]) {
int i,j,temp=0;
char z[50]={'0'};
for(i=0;i<50;i++)

[Code] .....

View 9 Replies View Related

C++ :: Add And Subtract Two Sets Of Integer Arrays?

Apr 24, 2013

Ok so I am currently trying to add and subtract two sets of integer arrays. When I run my program, the program does not subtract the numbers from the first set with the numbers from the second set. Could anyone here take a look at my code and help me figure out what the problem is?

#include <iostream>
#include "SafeArray.h"
using namespace std;

[Code].....

View 1 Replies View Related

C :: Why Program Can't Subtract Negative Number From Positive One

Feb 2, 2015

My program uses a while loop to eventually get to an error of zero and a root of sqrt(3). I'm not understand why after the third iteration the program fails to compute a new x value. I'm using Visual Studio 2013. The code tag instructions were dubious.

Code:

#include <stdio.h>
#include <math.h>
main() {
/*This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots.*/
printf("This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots. Enter your estimate of the root.
");
float x,y,z;
int num;
num = 0;

[Code]...

View 1 Replies View Related

C :: Store Character Array In Reverse Order Then Display Reversed Array

Jun 14, 2013

The program should store a character array in reverse order then display the reversed array. I have also included in the code that will display the actual characters into the array as it loops through. So I know the characters are being stored, but why doesn't it display the entire string when I call it?

Code:
#include<stdio.h>
int main(){
char str[50];
char rev[50];
printf("Enter Desired Text: ");
scanf ("%[^

[Code] ....

Is it just my compiler?

View 5 Replies View Related

C++ :: Program That Add / Subtract / Multiply Or Divide Two Integers - Incorrect Answers

Oct 7, 2012

Create a program that adds, subtracts, multiplies, or divides two integers. The program will need to get a letter (A for addition, S for subtractions, M for multiplication, or D for division) and two integers from the user. If the user enters an invalid letter, the program should display an appropriate error message before the program ends. If the letter is A (or a), the program should calculate and display the sum of both integers. If the letter is S (or s), the program should display the difference between both integers. When calculating the difference, always subtract the smaller number from the larger one. If the letter is M (or m), the program should display the product of both integers. If the letter is D (or d), the program should divide both integers, always dividing the larger number by the smaller one."

And here is the test data. I am posting the results from my desk-check table.

operation first integer second integer answer
A 10 20 30
a 45 15 60
S 65 50 15
s 7 13 6
G -1
M 10 20 200
d 45 15 3
d 50 100 2

Then, I transferred my program into a source file. Here it is:

//Exercise16.cpp - display answer of two integers

#include <iostream>
using namespace std;
int main() {
//declare variables
int firstInteger = 0;

[Code] ....

After putting in the data, everything worked fine, except the last two operations, which are M (multiplication) and D (division). All the answers for the last two operations essentially give me a 0.

View 4 Replies View Related

C++ :: Calculator That Takes Two Large Numbers In Linked List Then Ask User To Add Or Subtract

Dec 30, 2012

What I'm trying to do is make a calculator that takes two large numbers in a linked list then ask the user if they wish to add them or subtract them.

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

class Node {
public:
int value;
Node * next;

[Code] ....

View 5 Replies View Related

C/C++ :: Testing Character Array Against Array Of Characters?

Apr 16, 2014

I am currently having an issue with validating user input for a state abbreviation. I have an array where a list of abbreviations is stored to use as a comparison for whatever the user inputs. I have been able to get the list loaded properly but whenever i go to compare, it always comes back as true even if it isn't. Here is some relevant code:

static char stateTable[STATE_TABLE_SIZE][STATE_SIZE];
int main() {
char buffer[40], *testCustName[40], testState[5], testCode;
buffer[0] = '';
int quit = 0;
int p = 0;

[code].....

View 6 Replies View Related

C :: How To Move A Character In 2D Array

Jan 27, 2015

I want to move a character in a 2D array This Character should move vertically in a 2D Array To exemplify it for Exam in Snake Game A character automatically moves Please Write a example code that works

View 4 Replies View Related

C++ :: Repeat Character Array

Nov 1, 2013

I'm having a little trouble writing program that on remove all repeat characters and leave only the non repeated characters. This is want I have so far.

#include <iostream>
#include <cstring>
#include <string>
unsigned repeatingCharCount(char const* s) {
std::string unique ;
const unsigned length = std::strlen(s) ;

[Code]...

View 6 Replies View Related

C++ :: Floating Value From Character Array

Dec 9, 2014

How to extract a floating value from a character array in separate variables .

Example : multiply 7.5 with 2

Out put : 7.5 , 2

View 1 Replies View Related

C++ :: How To Delete First Character In Array

May 1, 2014

How do i delete the first character in a character array?

I want output to be

void DeleteFirst (char S[ ])
{
for( int i = 1; i < MAX_LENGTH; i++)
cout << S[i];
}

i am just writing the wrest of the Array without deleting the first. how do i delete the first?

View 7 Replies View Related

C++ ::  add A Space Into Character Array

Apr 29, 2014

I have a character Array 'Hello'

I want to add a space in whatever space the users chooses.

"Where do you want to add space? --> " 3 String after space is added --> 'Hel lo

View 4 Replies View Related

C/C++ :: Clear First Character Of Array

Mar 26, 2014

I am trying to clear the first character of my array. The first two methods don't seem to work. The third method seems to but doesn't look like a good idea.

char operand[] = "abc";
//both methods seem to null it out
operand[0] = 0;
memset(operand, 0, 1);
printf("%s", operand);

//seems to work
memset(operand, 5, 1);

View 4 Replies View Related

C++ :: Making Constructor For Array Of Character

Jan 16, 2015

Code:
class Robot{
char name[15]; //assign to char n
int x, y , direction;
void ToString(int d);

[Code]......

how do i assign char name[] in the class to char n in the constructor?

View 3 Replies View Related

C :: Storing Integers To Character Array?

Jan 30, 2013

I am creating a program and am having trouble with one part. The input file looks like:

Code:
2
3
Bill Jeff Steve
Linda Brittany Jessica
3 1 4
2 1 9
8 3 7
6 4 9
4 8 9
6 9 4

Where I am stuck is putting the numbers into the string array. For example, Bill's scores should be set up as Bill's scores should be set as

Code: bill_score = {3, 1, 4}

and when this code is ran

Code:
for (i=0; i<3; i++) {
printf("%s - ", men[i]);

[Code].....

View 4 Replies View Related

C :: Using Malloc For Array Of Character Pointers

Mar 30, 2013

I am able to work with n instances of a structure in one mallocated area, but when I try to do the same thing with just character pointers, I get compiler errors about making integer from pointer without a cast. If I create a structure with just a character pointer in it, it works just fine... I am just not seeing something here!!!

This works:

Code:
#include <stdio.h>
#include <stdlib.h>
int main (void) {
struct items {
unsigned int item_1;
unsigned int item_2;

[Code]...

This DOES NOT work!

Code:

#include <stdio.h>
#include <stdlib.h>
int main (void) {
char * items_ptr = NULL;
unsignedint i = 0;
char * one = "one";
char * two = "two";

[Code]...

View 9 Replies View Related

C++ :: Character Array To Wide String?

Nov 19, 2013

I am still working on my project which will be reading some old data from some old DOS files. The data stored there is naturally, char*. Once I read in my character array, how do I assign this to a wstring since my application is UNICODE?

Here is my current solution:

wchar_t* Class::Function(char *pName) {
//I verify the pointer and such first, then do the below
this->_Name.assign(pName, (pName + strlen(pName));
return this->_Name.c_str();
}

Am I on the right track here?

View 9 Replies View Related

C++ :: How To Count Character Occurrence In Array

Jan 17, 2015

i have a problem i cant find a way to count how many times a character occur in a character array the out put should be

a=2
b=1

but my output is

a=2
b=1
a=0

i cant find away to get rid of the other a letter i dont know what to do

#include <iostream>
using namespace std;
int main() {
char array[3] = {'a','b','a'};
char frequency[26] ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

[Code]...

View 2 Replies View Related

C++ :: How To Create Character Array That Has 128 Bytes

Sep 23, 2014

m_sName-- character array shall be 128 bytes

How do i create a character array that has 128 bytes?

View 1 Replies View Related

C/C++ :: Using Pointers For Character Array In For Loop

Nov 3, 2014

I'm taking an intro to programming course and my assignment is to Write a very simple program that uses two for loops and ONLY pointers and pointer arithmetic (NO other variables are allowed) to display a palindrome forward then backward. Declare the palindrome as follows: char str[] = “Straw Warts”; Well my prof never did anything with char arrays and I can't quite fit make the pointers work in the loop. This is my code. It runs how it should, i just can't seem to make a working for loop. It always says that you can compare int and char

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

[Code]......

View 7 Replies View Related







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