neovstan
Like how to use them later
You can use a number just in cycle after its getting from std::cin, but if you want to use it subsequently, you can store them all to container. E.g.: int count{}; std::cin >> count; std::vector<int> numbers; for (int i = 0; i < count; ++i) { int number{}; std::cin >> number; numbers.push_back(number); }
кар карыч
Thanks
neovstan
Next, you can get any value from vector numbers by this way numbers[0], numbers[1], numbers[2], etc
neovstan
Thanks
It should be understandable to you if you have ever programmed in other languages
кар карыч
and how to make a loop that will check if number[1] > S, then it adds up with number[0], and if number[1] <S, then it skips it, and so on until the last number
кар карыч
I'm sorry if I bored you)
Anonymous
how to print
Talula
how to print
Print what? And where?
neovstan
and how to make a loop that will check if number[1] > S, then it adds up with number[0], and if number[1] <S, then it skips it, and so on until the last number
If I understand you correctly, the past number must be added to each number, if each number is greater than S: for (int i = 0; i != numbers.size(); ++i) { if (i > 0 && numbers[i] > S) numbers[i] += numbers[i-1]; }
кар карыч
Thx
neovstan
Thx
Be careful, the addition will be produced if each number is greater than S, but not if they're equal
neovstan
how to print
😕 #include <iostream> int main() { std::cout << "Hello, world" << std::endl; }
X
pbuf1 = (char*)VirtualAlloc(NULL, // System selects address 100, // asks for 100 bytes MEM_COMMIT, // allocate committed memory PAGE_READWRITE); // protection = read and write printf("The first buffer allocated at : 0x%x\n", (DWORD)pbuf1); while (count < 100) *(pbuf1 + count) = 'a'; count += 1; //allocate the second the buffer pbuf2 = (char*)VirtualAlloc(NULL, // System selects address 100, MEM_COMMIT, PAGE_READWRITE); count = 0; printf("The second buffer allocated at: 0x%x\n", (DWORD)pbuf2); while (count < 100) *(pbuf2 + count) = 'b'; count += 1; //free buffers VirtualFree(pbuf1, 0,MEM_RELEASE); VirtualFree(pbuf2, 0,MEM_RELEASE);
X
it does not print the second buffer ?
кар карыч
Anonymous
did it
neovstan
it does not print the second buffer ?
Be more specific in your question
neovstan
how to store this result in a variable? for future use
Modified values of numbers are stored in your numbers vector
кар карыч
But… if I need to get the result in (sum2)
кар карыч
supposedly it should add up all the received numbers and write them down
neovstan
supposedly it should add up all the received numbers and write them down
Do you need to get the summary of all modified values in vector?
neovstan
If I understand you correctly, the past number must be added to each number, if each number is greater than S: for (int i = 0; i != numbers.size(); ++i) { if (i > 0 && numbers[i] > S) numbers[i] += numbers[i-1]; }
Modify this code to (If I understand you correctly, again): int amount{}; for (int i = 0; i != numbers.size(); ++i) { if (i > 0 && numbers[i] > S) numbers[i] += numbers[i-1]; amount += numbers[i]; }
neovstan
If you want to add only MODIFIED values, then put amount += line into if: int amount{}; for (int i = 0; i != numbers.size(); ++i) { if (i > 0 && numbers[i] > S) { numbers[i] += numbers[i-1]; amount += numbers[i]; } }
кар карыч
And the result will be written to (amount)?
кар карыч
cout << (amount)?
ʙʀʜᴏᴏᴍ ⑇
HW_3.cpp:331:12: error: conflicting declaration 'std::string destinationFile' 331 | string destinationFile = "C++/HomeWorks/sodoku/board.txt" | ^~~~~~~~~~~~~~~ HW_3.cpp:326:10: note: previous declaration as 'char destinationFile [256]' 326 | char destinationFile[256];
ʙʀʜᴏᴏᴍ ⑇
any one plz!?
Dima
you better show the whole code
ʙʀʜᴏᴏᴍ ⑇
ofstream fout; char destinationFile[256]; string destinationFile = "C++/HomeWorks/sodoku/board.txt" if (fout.fail()) { cout << "Output file opening failed.\n"; exit(1); } else cout << "Board written successfully";
Dima
char destinationFile[256]; string destinationFile why and what is the reason?
Dima
you cant use duplicating variable name
Dima
error basically says the same
Dima
remove the second line
ʙʀʜᴏᴏᴍ ⑇
oh!! I see ... my bad
ʙʀʜᴏᴏᴍ ⑇
Koorosh
hi
Koorosh
Friends who have apps are programming. I can bring the rap program to the top of the Play Store with Google Play's comment service. For service, visit Pewi.
Anonymous
you cant use duplicating variable name
If you still want to use destinationFile twice as variables, then change the case of one since c++ isn’t case sensitive
neovstan
ofstream fout; char destinationFile[256]; string destinationFile = "C++/HomeWorks/sodoku/board.txt" if (fout.fail()) { cout << "Output file opening failed.\n"; exit(1); } else cout << "Board written successfully";
By the way, if you declare a variable of concrete type (non-user-defined, such as char, int, float or any kind of arrays like your char[256]), you have to initialize it on its definition by default value. It prevents a lot of problems (caused by lack of default initialization and subsequently using of non-initialized variable with undefined value) while you’re beginner in language (you can make mistakes). Do like this: // code in some function int a{}; char c{}; char arr[256]{}; etc. It would be better to initialize even “user-defined” types, but you don’t have to do it: // code in some function string a{}; string b; // There is no difference between a and b However, you don’t have to do it, if you declared a variable in global namespace or specified it static. // global namespace int a; // good // any namespace static int b; // good
Anonymous
how to insert graphics.h in cxxdroid
Anonymous
What's the meaning of % in coding of C
Anonymous
What's the meaning of % in coding of C
It assigns a character integer or float memory as you execute your code
abdullah reveha
hello i have an assigment and i am not able to create correct algorithm to solve assigment. could you help me please? ASSIGMENT Horizontally best fit tetris We will ask user to how many tetrominos you will use and we will ask again which ones you will use. According to the tetrominos we must print horizontally best-fit on the screen. EXAMPLE OUTPUT: How many tetrominos? 3 What are the types? O T L Horizontally best-fit tetrominos: T OOTT L OOTLLL
Anonymous
Denys
Hello, l have a question about my task. I need to copy 3 elements of array of 9 elements to another and sort it. l am exactly copy elements, but l am trying to sort it and nothing happens
Denys
Hello, l have a question about my task. I need to copy 3 elements of array of 9 elements to another and sort it. l am exactly copy elements, but l am trying to sort it and nothing happens
#include <stdio.h> int main(void) { int array[9] = { 50, -1, 99, 46, -4, 70, 85, 4, 10 }; int length = sizeof array / sizeof array[0]; int temp; int i, j, k; int array2[3]; for (i = 0; i <length; i++) { printf("%d ",array[i]); } printf("\nCopy 3 elements into array2: "); for (i = 0; i <length-6; i++) { array2[i] = array[i]; printf("%d ", array2[i]); } for (k = 0; k < array2[i]; k++) { for (j = 0; j < array2[i] - 1; j++) { if (j > k) { temp = array2[k]; array2[j] = array2[k]; array2[k] = temp; printf("%d ", array2[i]); } } } }
Denys
my copying array is 50 -1 90 so when l running through array l campare the next( for (i = 0; i <length-6; i++)) and previous ( for (j = 0; j < array2[i] - 1; j++)) elements
Ilya
for (k = 0; k < array2[i]; k++) This line is rly strange. In your example this loop will repeat 50 times
Ilya
it's like buble sort
for (k = 0; k < array2[i] here must be the length of array2, not an item in the strange position; k++) if (j > k) - what is the point in comparing indexes? You must compare items of array
cez
excuse me all, i try to connect c++ visual studio to sql. but it fail bcs exception unhandled at memory. any idea?
Denys
for (k = 0; k < array2[i] here must be the length of array2, not an item in the strange position; k++) if (j > k) - what is the point in comparing indexes? You must compare items of array
for (k = 0; k <array2[3]; k++) { for (j = 0; j <array2[3]-1; j++) { if (array2[j] > array2[k]) { temp = array2[k]; array2[j] = array2[k]; array2[k] = temp; printf("%d ", array2[i]); } }
Anonymous
enum class Tetrominos {I,O,T,J,L,S,Z}; int main() { int all_tetrominos = 3; Tetrominos x; cout << "What are the types?" << endl; while(all_tetrominos>0) { cin >> x; // problematic line all_tetrominos--; } } How can I fix this code? cin >> x; line is problematic
emiteclap
>=
Dima
bruh
JHex125
Has anyone run into a case when vector fail to initialize with given initialize value by resize? I want to know it doesn't work.
JHex125
I have a vector map and a enum class Grid, I want to initialize all the elements with map.resize(MAP_WIDTH, Grid::coin), but it doesn't work, and when I use for loop, it works.
_VVV_
Hey! Help solve problems. I using the EnumProcesses method, I got a list of processes, how can I now select system and user?
Yuvraj
has anyone given deutche bank graduate analyst oncampus test?
olli
How to separate processes into user and system?
what do you mean by that? On Windows there is exactly one System Process, usually with ID 4. Do you mean which processes have user mode parts? Or processes which have been started by the system?
neovstan
In the second case you don’t have to do it because they’re classes and default constructor is called
That’s right, but I said it would be better to do because of making a habit of list-initialization and specifics
olli
If you open the task manager, there will be user and system processes
in this case you can try something like this to get the user name for a process https://stackoverflow.com/a/8992043
_VVV_
EnumProcesses(ProcessesIDs, sizeof(ProcessesIDs), &cbNeeded); cProcesses = cbNeeded / sizeof(DWORD); for (i = 0; i < cProcesses; i++) { if (ProcessesIDs[i] != 0) { HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessesIDs[i]); //__ HANDLE token = 0; DWORD nlen, dlen; TOKEN_USER* ptu; char name[300], dom[300], tubuf[300]; int iUse; if (NULL != hProcess) { GetModuleBaseName(hProcess, NULL, szProcessName, sizeof(szProcessName) / sizeof(TCHAR)); } actualValue.insert(ProcessesIDs[i]); OpenProcessToken(hProcess , TOKEN_QUERY, &token); ptu = (TOKEN_USER*)tubuf; GetTokenInformation(token, (TOKEN_INFORMATION_CLASS)1, ptu, 300, &nlen); LookupAccountSidA(0, ptu->User.Sid, name, &nlen, dom, &dlen, (PSID_NAME_USE)&iUse); cout << name << endl; CloseHandle(hProcess); } }
_VVV_
Did not work out
Anonymous
#include <stdio.h> #include <math.h> int main ( ) { int a; printf("enter number : "); scanf("%d \n", &a ); printf("%d \n ", a>9 && a<100); int sum = a>9 && a<100; return 0; What's the error in it? OUTPUT: I ENTER THE NUMBER BUT IT IS NOT GOING FORWARD ⏩⏩ IT JUST STOPPED WHYY?