Print all data on terminal and ask for input

Hey, I was wondering if there was a way to do something like this on the terminal.

Part Name: (input)
Description: input_desc
Availability: input_quant
Price: input_price


But in a way so that it always shows

Part Name:
Description:
Availability:
Price:
Yeah, you just need more then the default level of control that a simple C++ app gives you over the consule. What platform are you writing on? What libs are you familar with?
Dont exactly get ur question...but from what i get it...do it in a while loop. I have no idea what is your control factor but ill give you an example. Not sure if this is what u mean but have a look...
1
2
3
4
5
6
7
8
9
10
int condition;

do
{
... //all your couts and cin

//finally
cout<<"enter 0 to exit"<<endl;
cin>>condition;
}while(condition);


I have skipped error checking, please do it(check if condition is an integer)


This will do what you need in a loop...There are many ways you can do it though
Hi Computergeek01,

I'm just starting (couple of college classes, but I still feel like I'm just starting) in C++ programming, so I'm not familiar with many libraries. Right now I'm switching between Visual Studio 2010 (Windows 7) for college work and Code::Blocks (Ubuntu) for messing around.

I was just curious on how it is achiveable in C++, for like self-learning, practice.

Thanks.
I think the OP wants the display to always have those items listed, then have the cursor start at "Part Name:" then move down to "Description:" and so on. In which case all of the 3rd party libs I regularly work with (Win32, SFML and SDL) allow you to reposition the cursor. You just have to use a different approach then "std::cout".
What geek is trying to say, the standard output functions would not work because they work with sequential output.
@jackell777

Yeah, but like that will print the other "couts "AFTER the user inputs the "part name", etc. I ment it so it prints all the "couts" and then wait for user input so that it prints the data.

Part Name:
Description:
Availability:
Price: $


after user enters part name:

Part Name: Example
Description: Example's description
Availability: 20
Price: $ 30.00


Last edited on
@ OP: You'll need to be familiar with at least one of these libraries. I recommend SFML, you can pick up on how to do this in about an afternoon and come here if you have any questions.
@Dukaim:

I know what you mean. Okay in that case you will have to have a class of these parts stored somewhere in a list structure or other data structure. U can use STL library. Once the user enters a partname, you search through the list to find the matching partname and then get the other info and print them...
Oh, nevermind. This is simpler then I thought it would be :p.

NOTE: I'm not the OP.
I did a search on modifying cursor position and I found:
1
2
3
4
5
6
7
8
9
10
11
#include <windows.h>
#include <iostream>
using namespace std;

void gotoxy( short x, short y ) {

HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { x, y };

SetConsoleCursorPosition( hStdout, position );
}


Using that I did a little driver to try it out and it worked like I wanted. I know it has some system("cls"), but it was just a quick code so I could show you guys what I meant.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;

void gotoxy( short x, short y ) {

HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { x, y };

SetConsoleCursorPosition( hStdout, position );
}

int main()
{
	string PartNumber[] = {"MD136466", "5J1"};
	string description[] = {"Air Filter, Genesis Coupe 2010", "Crazy Glue"};
	string input;
	double price[] = {10.99, 1.99};
	int quantity[] = {20,50};
	int i;

	while(true)
	{
		cout << "Part Number: " << endl;
		cout << "Description: " << endl;
		cout << "Quantity: " << endl;
		cout << "Price: $" << endl;
		gotoxy(13,0);
		getline(cin, input);

		system("cls");

		for(i = 0; i < 2; i++)
			if(input == PartNumber[i])
			{
				cout << "Part Number: " << PartNumber[i] << endl;
				cout << "Description: " << description[i] << endl;
				cout << "Quantity: " << quantity[i] << endl;
				cout << "Price: $" << price[i] << endl;
			}
		gotoxy(0,0);
	}
	return 0;
}
Ok, this is the Win32 API like I mentioned before. I think SFML would have been easier to understand but if you've got it then good to go.
@Computergeek01

Well, it does what I wanted but I want to understand it :P ... I'll take a look at SFML once I get it to install on VS2010, I wanna keep learning these type of things, Thanks :D
k now i get what you exactly wanna do....but this is a bad programming style..cos it does not give way to expansion and deletion. Say the programer accidentally deletes partNumber[i] without also deleting the rest at that ith location. And then he inserts a different partNumber[i] at that ith location, then the info you produce will be not correct one.

My suggestion is to use stl, where when u delete a partNumber[i], all the members associated with it also gets deleted.

There are more conceptual errors with your code here though it will work just fine but not good for dynamically emerging code.
Last edited on
Topic archived. No new replies allowed.