Hello I have a question concerning this example flow chart.
Here I am reading an integer from a database table. the integer can be something between 1-10.
I want to make different outputs concerning this integer, like if int ==1 then show "Hello World 1", if int ==2, then "Hello World 2".
That's ok - but is there any technique to shorten that with i or x? what it would look like then?
thank u
TWO cases
CASE 1: if you really want to show 2 if INT == 3
On the False of IF INT == 1 set the output to Show Hello World 2
(no extra true/false)
CASE 2: if you actually want to show 3 if INT == 3
Just put the SHOW box directly after READ INT FROM TABLE AS Show HEllo World INT
Related
This question already has answers here:
C++ Update console output
(4 answers)
Closed 5 years ago.
I'm developing some application in which I want to manipulate some data comming from the embedded system. So, what do I want to do is that I want to display the values which are comming on the same position where they were before, leaving the static text on the same place and not using new line. Being more specific, I want to output my data in form of a table, and in this table on the same positions I want to update that data. There is some analogy in Linux, when in the terminal there is some update of the value(let's say some progress) while the static text remains and only the value is changing.
So, the output should look like this:
Some_data: 0xFFFF
Some_data2: 0xA1B3
Some_data3: 0x1201
So in this case, "Some_data" remains unchanged on the same place, and only the data itself is updated.
Are there maybe some libraries for doing that? What about Windows Console Functions? Also, it would be very nice if it could be made in such a way, in which the console would not flick, like when you clear the console and print something back. Any hints or suggestions? Thanks very much in advance guys!
P.S. There is no need to write the code, I just need some hints or suggestions, with very short examples if possible(but not required).
On a *nix system you have two options.
1) If you want to manipulate the entire console in table form like you ask, then ncurses is the best option. The complete reference can be found here.
As you can see, that package is quite heavyweight and can often be overkill for simple projects, so I often use . ..
2) If you can contain your changing information on a single line, use the backspace escape char \b and then rewrite the information repeatedly to that line
For example, try this . . .
#include <iostream>
#include <chrono>
#include <thread>
using namespace std;
void writeStuff(int d)
{
cout << string(100,'\b') << flush;
cout << "Thing = " << d;
}
int main()
{
cout << "AMAZING GIZMO" << "\n============" << endl;
while(1) {
writeStuff(rand());
this_thread::sleep_for(chrono::milliseconds(250));
}
}
For a real world example, the sox audio console playback command uses this technique to good effect by displaying a bar chart made of console characters to represent the audio playback level in real time.
Of course, you can get more creative with the method shown above if your console supports ANSI escape sequences.
I want to count integers from .txt file named "Example.in", which contains (for example):
1 2 3 4 5
3 6 7
5 8
8 9 10 11
1. and returns me a 11, in this case (Integers that repeat counts as 1 - unique number count only). At this point, it only prints out 0 (I think there's problem with opening file at this stage).
2. prints out only the first integers in every row - 1, 3, 5, 8.
int integer_count(){
int count = 0;
int i;
ifstream fin;
fin.open("Example.in"); //.txt file
while(fin >> i)
{
count++;
}
fin.close();
return count; // In this case it should print 14 instead of 11,
because I didn't count out 3, 5 and 8 (which duplicates - haven't figured
out how to make unique count that would close eye for duplicates and
just count unique integers.)
}
When opening the file, you should always check whether or not the opening process has succeed. I believe that file_name.good() is a perfect boolean function to do that. Just make a simple if statement to see if it works, like that:
if(fin.good()) std::cout << "File opened!";
else{ //do something when opening didn't work }
Additioanlly, I believe you also need to write the 'full file name', which in this case (if your file name is exactly "Example.in") would be "Example.in.txt".
For the unique integers problem, there are couple solutions: either make a std::vector that stores already read integers from file and everytime you try to read another one, check whether or not it was already read (fastest algorithm here would be quick/heap/merge sort + binary search, instead of iterating everytime). Always when new integer is added, increase your count value by one.
Second solution is: just store your integers in vector and get rid of the multiples by iterating and erasing. Then count would just be your_vector.size().
"Printing each integer that starts a new line" is a diffrent problem. I would switch from using while(fin >> i) to getline() function. That way, I have each line of file as a string, that can be turned into row of integers. With your while() loop, you do not know when the new line stars, so it's impossible to complete second task (or, after the task 1, you could open a file once again and use another algoritm only for getting the first integers of every line)
Last thing: As many people here stated, using a debugger is highly recommended. It saved me hours of pondering what is wrong, by just simply going through code, line by line. Codeblocks offers a really good debugger, so I encourage you to simply google a codeblocks debugger guide. Even YouTube has some tutorials covering that.
I have a int containing a value like this:
int CharY = 20;
And I want that value to increase with 1 until it is equal to lets say 50.
But I dont want it to do like this:
I would more likely make the value smoothly increase something like this:
How can I achive this like in picture number 2 without a ton of code and such?
If you are familiar with a little math, you should be able to understand the window function. So let's say 20 is the start point and 50 is the top(middle of window). Pick a function, decide the sample count, use a timer tick and sample a value from the function for every tick.
By the way, I find the welch window easiest.
Gokhan.
I have some lines of code in a Stata do-file that I would like to reuse/execute and different points in the do file. Similar to a JavaScript function... however I do not necessarily need an input variable.
For example, I have some code:
*code to reuse
foreach x in test1 test2 test3{
rename variable_`x' variablenew_`x'
}
and I want to execute those 3 lines of code at various points in the do file. As if there was a way to label those three lines codeA and then execute codeA later in the do file.
Any suggestions?
Check help program.
An example program (that takes no arguments):
// define program
capture program drop hello
program hello
display "hello world!"
end
// try it out
hello
This is hopefully a simple linker issue but I've spent hours searching and haven't moved forward in that time. I'm trying to use
#include <cmath>
double aA = 2;
double result = pow((double)2.0,(double)aA);
I get no error messages and it compiles without issue. But an unrelated grid I'm drawing with openGL doesn't display. If i substitute the aA for 2 then it displays the grid. Like
#include <cmath>
double aA = 2;
double result = pow((double)2.0,(double)2);
This outputs 4 as expected. The previous example outputs nothing. It's as if the program hangs but there are no errors.
This computation isn't used anywhere and in fact just sits in main (or anywhere else) and the variables are unique and are unused.
I'm using code::blocks and minGW GNU GCC compiler in Windows 7. -g -Wall - WExtra
Rendering with glew + freeglut and everything else works until i use a variable with pow.
I've tried every combination of casting I can think of and I've tried powf with the exact same result. I'm using sqrt and other functions so believe that the inclusion is working. I've also tried math.h but get the same problem.
I have never wished to see an error message from a compiler more so than I do right now.
So 1. Why am I not getting an error when it looks like its stopping the whole program in its tracks?
And 2. What have I missed to get pow() working with variables?
Update : After creating a new project and trying it out I have no issues so there must be something in my setup that's interfering. I'll keep experimenting. Thanks for the quick responses things sure move fast around here!
Update 2:
Very strange.
float aAs = 1.0;
float amplitudeA = (float)pow((float)2.,(float)aAs);
char str[50];
int test = (int) (amplitudeA);
sprintf (str, "out - %d", test);
MessageBox(NULL,str,NULL,NULL);
This outputs 2 in the message box. Then my grid draws and the program behaves. If i comment out only the message box like so:
float aAs = 1.0;
float amplitudeA = (float)pow((float)2.,(float)aAs);
char str[50];
int test = (int) (amplitudeA);
sprintf (str, "out - %d", test);
//MessageBox(NULL,str,NULL,NULL);
No drawing of my grid. What could be causing this?
char str[50];
int test = (int) (1);
sprintf (str, "out - %d", test);
MessageBox(NULL,str,NULL,NULL);
float aAs = 1.0;
float amplitudeA = (float)pow((float)2.,(float)aAs);
Swapping the message box over recreates the issue. No grid drawn. It's as if focus needs to be taken away from the program when I'm using a variable in pow. I'm completely baffled.
Another Update : I temporarily got around it by writing my own simple powerOf function. But now I'm having the same issue with the cos() function.
Can anyone tell me if there is something wrong with that image? This issue has to stem from incorrect linking. Is that what you would expect from hovering over coz in code::blocks with gcc?
This a error that occurs only when running through the program with a bad cos call. Interesting that I've been using cos for camera calculations since I started this app with no issue.
Error #667: UNADDRESSABLE ACCESS: reading 0x00000003-0x00000007 4 byte(s)
# 0 ntdll.dll!RtlImageNtHeader +0x124c (0x77ca43d0 <ntdll.dll+0x343d0>)
# 1 ntdll.dll!RtlImageNtHeader +0x422 (0x77ca35a7 <ntdll.dll+0x335a7>)
# 2 ntdll.dll!RtlImageNtHeader +0x30d (0x77ca3492 <ntdll.dll+0x33492>)
# 3 KERNEL32.dll!HeapFree +0x13 (0x775e14dd <KERNEL32.dll+0x114dd>)
# 4 atioglxx.dll!atiPPHSN +0x11afaa (0x66538f3b <atioglxx.dll+0xeb8f3b>)
# 5 atioglxx.dll!DrvSwapBuffers +0x33fb (0x6569b9cc <atioglxx.dll+0x1b9cc>)
# 6 atioglxx.dll!DrvSwapBuffers +0x3cad (0x6569c27e <atioglxx.dll+0x1c27e>)
# 7 atioglxx.dll!DrvSwapBuffers +0x7c57 (0x656a0228 <atioglxx.dll+0x20228>)
# 8 atioglxx.dll!DrvSwapBuffers +0x12c (0x656986fd <atioglxx.dll+0x186fd>)
# 9 atioglxx.dll!DrvValidateVersion +0x28 (0x65697c19 <atioglxx.dll+0x17c19>)
#10 OPENGL32.dll!wglSwapMultipleBuffers +0xc5d (0x66c8af0b <OPENGL32.dll+0x3af0b>)
#11 OPENGL32.dll!wglSwapMultipleBuffers +0xe45 (0x66c8b0f3 <OPENGL32.dll+0x3b0f3>)
Note: #0:00:05.233 in thread 3136
Note: instruction: mov 0x04(%ecx) -> %ecx
Solved. There was an uninitialized variable that was sitting at the bottom of the vertex buffer object I was using to draw the grid. For whatever reason feeding a variable to one of the math functions caused unexpected results in this buffer object.
Thanks to Angew an Kos for pointing me towards memory.