ok everyone, i taking my first semester of C++ and i have a little quesiton, the teacher wants up to output and input on the same line, but to send the input through i have to strike enter, which keys to the next line, heres my code, just cant get it to work how i want it

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const string MY_NAME = "Devon Crampton";
const string COURSE_NUMBER = "Lab 1 CST 113 -03";

const int YEAR = 2008;
const int RAWWOOL = 8;

const double SHEAR_COST = 2.25;

	
	int main (void)
{

	double inputWoolPrice;
	
	double year = YEAR;
	double price1;
	double price2;
	double price3;
	double yearPriceWool;
	double totalWool;
	double shearTotal;
	double rawProfit;
	
	int totalSheep;
	int wool1;
	int wool2;
	int wool3;
	int numberOfSheep1;
	int numberOfSheep2;
	int numberOfSheep3;
	
	// Output to the screen programmer's name and course number
	cout.fill('*');
	cout << setw(70+1) << " " << endl;
	cout.fill(' ');
	cout << endl;
	cout << MY_NAME << endl;
	cout << COURSE_NUMBER << endl;
	cout << endl;
    cout.fill('*');
	cout << setw(70+1) << " " << endl;
	cout.fill(' ');
	cout<< endl;

	// input price of wool
	cout << " What is the selling price per pound of sheared wool for 2008? :  ";
	cin >> inputWoolPrice;

///----------------------------------------------------------------------------------	
/// this is where i am having the problem  \/
	// input number of sheep in each field
	cout << " Enter the number of sheep sheared from each field for 2008 :  "<< endl;
	// i have to have these 3 inputs and outputs on the same line
        cout << " field 1 "; cin >> numberOfSheep1;
	cout << " field 2 "; cin >> numberOfSheep2;
	cout << " field 3 "; cin >> numberOfSheep3;

///----------------------------------------------------------------------------------	
	cout.fill('*');
	cout << setw(70+1) << " " << endl;
	cout.fill(' ');
	cout<< endl;

right now they output like this


Enter the number of sheep sheared from each field for 2008 :
field 1 259
field 2 147
field 3 369

i need to have it output like this

Enter the number of sheep sheared from each field for 2008 :
field 1: 259 field 2: 147 field 3: 369

so that every time i strike enter or space it displayed the next output and prompts me for the input

any ideas, this one is stumping me, my tutor couldn't even help me..

thanks for the help !

I would first verify with your teacher whether this is really what he wants, because that is not easy to do, in fact, you probably can't do it without an extended IO library (such as conio.h or curses.h).

I would suggest you just avoid the problem and do this:

// input number of sheep in each field
  cout << " Enter the number of sheep sheared from 3 fields for 2008 : ";
  cin >> numberOfSheep1 >> numberOfSheep2 >> numberOfSheep3;

Then the user can enter the three fields, separated by a space.

thanks make, thats how i did it originally, i just wanted to see how hard it would be to make it look better, the professor said it could be formatted however we wanted, but the way u described is generally the way she expects it

thanks again!

If you still wish to do all the outputs and inputs on the same line, the '\b' character might work. You could possibly use it to delete the newline character. Just a thought.

One way I know for sure works though is using the Windows.h SetConsoleCursorPosition(). See:
http://www.adrianxw.dk/SoftwareSite/index.html

Or you could try looking up the getch() function to get input w/o waiting for ENTER key.

Hope this helps!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.