C/C++ :: Finding Optimized Parts By Length?
Feb 4, 2015
I am trying to put together a parts ordering calculator for work, and I am trying to figure out what the best to get what parts to order based on the length of the unit and the length of the parts.
So for example I have a counter that is 600 inches long, and I have 3 type of railings that we would use. The first one is 17 inches, the next one is 14 inches and the last one is 11 inches.
The idea is figuring out how many ( Combination of the 3 ) of the 17, 14 or 11 inch railings does would it take to meet the 600 inches. If it ends up going over, then we can cut it size, but I want to get as close as possible.
So in this situation if the counter is 634 inches, then we would order:
35x 17"
2x 14"
1x 11"
So I would have to write an algorithm i guess to get the best combination of the 3 length of railing to fit the counter with as little excess as possible.
View 3 Replies
ADVERTISEMENT
Oct 22, 2013
How you'd type yes or no scenarios for a text based RPG? And I mean a really basic like 'you see ..... what do you do?'. Also, how would you finish a code like this.
View 9 Replies
View Related
Feb 25, 2015
I'm Getting exceptions on Windows 7 and Windows 8 on different parts of the Code? Why this can be happening, why the difference in behavior?
View 6 Replies
View Related
Jan 1, 2014
I am currently working out on a problem in which a c program is to be made which shows a large text file in parts.
f
For example: If file contains 200 lines. 50 lines will be shown on first page and user is asked to press any key to move to next page until EOF is found. user is allowed to return to previous page as well, and this is very complicated task for me. I tried to move cursor to a specific position using fseek etc but it page doesn't stop and reaches to end quickly.
View 1 Replies
View Related
Feb 1, 2015
I have had experience in programming from python (slightly related, html/css) and the computercraft from minecraff (basic i think it is).
My question is mainly about the C and past experience with the computercraft.
1. Is it possible to split the command console into 2 parts (a visual area and a text area)
2. Is it possible to use any form of pixel art or custom characters within any command console using C.
View 2 Replies
View Related
Jul 30, 2013
im trying to read in 1 array and get 2 as outputs from 3 different functions.my read array is easy enough were im getting confused is how to read that array, separate it and take out only the parts i want and place them into a 2nd, then again a 3rd array.i have the following so far:
Code:
#include<stdlib.h>#include<stdio.h>
#include<unistd.h>
#define SIZE 10
}
[code]....
this compiles without a complaint, but when i go to run it no longer responds after taking the 10th element (well 9th if counting from 0).I think i have the if correct for the even odd section, but when i try to populate B or C array with the output of that if statement from A is were i think things are dying...
View 12 Replies
View Related
Dec 15, 2013
I am wondering if there is a way to compare two strings that aren't identical with each other.
instance:
str1="ABC123";
str2="A****3";
if(str1==str2) {
cout << "It's a match";
}
View 5 Replies
View Related
Nov 12, 2014
Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length
using System;
using System.Data;
using System.Configuration;
[Code]....
View 2 Replies
View Related
Nov 20, 2013
I'm trying some codes about string arrays and taking array length. But i have some problems. I can't get length of string and can't send to a function.
------------------------
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
void GetLength(string);
std::string Words[]={"table","gun","programming"};
int main()
{std::string InputWord;
[Code]...
And how can send Matrix to other function?
View 2 Replies
View Related
Oct 3, 2013
The programming problem is supposed to take a decimal number from a user and turn it into a binary number. Here is my code:
for (int i=0; i< count; i++) {
binary[i] = decimal % 2;
decimal = decimal/2;
} cout << binary[2] << endl;
decimal is the number entered by the user.
binary [] is the char array and count is... you know how many times the for loop will turn. So my question is, how do i know the length of the number ? Any function that shows the integer length ? because its impossible to know what count is equal to. like 100 is 3.
View 3 Replies
View Related
Jan 29, 2015
I need to be able to find every possible permutation using all possible values of a char. But I have to make it be able to form permutations from a length of 1 to variable N. For example, if N=3, I need it to be able to come up with
0x00
0x01
.......
0x00 0x00
0x01 0x01
.......
0xff 0xff 0xfe
0xff 0xff 0xff
How could I do this. (I would like to avoid recursion, since N might be as large as 50 or 60 and using recursion would most likely cause a stack overflow)
View 3 Replies
View Related
Apr 16, 2013
I'm working with arrays that might have NULL bytes in them and I'm wondering how to determine the length of the array or store it somewhere with the array (strlen() won't work because of the NULL, right?).
I've found advice like store the length of the array in the first byte of the array, but since sizeof(size_t) is 8 should I leave the first 8 bytes for the length?
Would it be better do define my own structure which would store the array and its length? What's the usual way these things are handled in practice?
View 7 Replies
View Related
Apr 20, 2013
Code:
char line[BUFSIZ];
while ( fgets(line, sizeof line, file) != NULL ){
llen = strlen(line);
printf("%d - %s
",llen,line);
}
I get a full line printed but my llen is the size of my buffer. how do i get the total size om my line from the beginning to " "
View 3 Replies
View Related
Feb 9, 2014
I was reading in a book I had about C that an array has at the very end a "null character" signifying the end of the string inside it, "/o". So that made me think, "I guess one needs to declare arrays as having 1 extra space than one expects the array to need. I wonder what will happen if I exceed the array length?" So I made a program to test it out. Here is the program/results:
Code:
#include <stdio.h>
int main(void){
char name[3];
printf("
What's your name?
");
scanf("%s", name);
}
[code]....
As you can see my name was able to fit in the array somehow even though I only allocated 3 bytes to the array. I tried again using my legal first name, Benjamin, and it was still able to fit. How is the array able to hold my name when I declared it as only having 3 bytes?
View 13 Replies
View Related
Nov 23, 2013
Any good function that get the length of an integer in C++
I do know of str.length(), however i want something similar for integers
View 1 Replies
View Related
May 24, 2013
i having a code to pass in array as argument, but the length returned is 1. This is not match with the array size.
int Getsize(int Array[])
{
int len = sizeof(Array)/sizeof(int);
cout << len << "
";
}
int main()
{
int X[] = {45, 12, 54, 83, 41, 36};
getsize(X);
}
View 19 Replies
View Related
Oct 5, 2014
im new to c++ ,so my question is how do i change a length of a text. for example hi my name is blah blah blah. nice to meet you. (n i want every lines to have 8 chars how do i do that)
(hi__my__
name_is_
balh____
blah____
blah____
._nice__
to_meet_
you.) (_ equal space)
View 3 Replies
View Related
Jul 6, 2014
int t;
string a;
cin>>t;
getline(cin,a);
int len=a.length();
cout<<a<<" "<<len;
[code].....
why is the length 0?what can I do to get the correct length of the input string?
View 5 Replies
View Related
Sep 7, 2013
I can't find any method of retrieving the length of an array except for doing this:
string first[] = {"a","be","see"};
int length = sizeof(first)/sizeof(first[0])
This is a very unconventional way of getting the length of an array.
first->length() would return 1 because it returns the number of letters in the first element of the array (which actually makes no logical sense).
first.size() would return 1 aswell as it's practically the same thing.
Since getting the length of an array is such a fundamental feat, how come I can't find a decent method of doing it?
Is there no buildt in method for this? If there is not, why has it not been implemented in the std?
View 3 Replies
View Related
May 28, 2013
The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.
it said 1 to 255 characters
i have to use getline(cin,str);
i tried str[255] but some error happen
View 2 Replies
View Related
Jun 16, 2014
I have a program with the following code, and I need to be able to either change the value of any or all of the strlen or to replace one or all with a temp array value. All values of the expression are arrays.
if (::strlen(tc_buf) + ::strlen(maxtime_buf) + ::strlen(" ") < sizeof(localBuf))
View 1 Replies
View Related
Jan 23, 2015
I'm trying to make an application and I need the length of the array of a struct. Like this:
struct myStruct {
int integer;
};
myStruct struct[] =
{
1,
2,
};
I want to get how many ints are in the array...
View 2 Replies
View Related
Dec 15, 2014
I am stuck here.
printf(" Enter a line of Morse Code for decrypting");
scanf("%s",phr);
len=strlen(phr);
for(a=0;a<36;a++) {
if(strcmp(phr, morse[a])==0)
printf("%c", alpha[a]);
};printf(" ");
The output :
[output] Enter line to encrypt:
..... -.... --...
converting...
5 [/output]
It should read all code, including null. between coded letter one space, between coded word three spaces.
The output should be:
[output]
56 7 [/output]
View 9 Replies
View Related
Feb 15, 2014
That is my routine to catch a text from editBox (ID_EDIT2) and save in a file. The address of file is in (ID_EDIT1). The code is working.
void simplewrite(HWND hwnd){
HANDLE hFile;
DWORD dwWritten;
[Code]....
My problem is: I put the size of char array txtbuffer=[200]. If I have a editbox bigger than that, I'll get a error. In (editlength) I have the correct length of edit box. But I cant initialize my char txtbuffer[editglenth]=NULL cause editlength is a integer not constant.
View 2 Replies
View Related
May 7, 2014
consider the following code:
string input;
getline( std::cin, input )
In the code above, what is the maximum number of characters that can be read into variable input?
View 4 Replies
View Related
Sep 20, 2013
Any way to get the length of a string? I have tried:
str.length
str.size
strlen()
Bob
Code:
// Exercise in string manipulation
#include <iostream>
#include <string>
void prtname(std::string str);
using namespace std;
int main() {
[Code]...
View 1 Replies
View Related