Hello I'm taking my first C++ class and I have really embarrassing question ( because I'm sure I'm missing something simple but I just can't figure out what): Why won't my output "dead loop" show after the do while loop ends with the user entering enter?

// This program will calculate the GPA of a given student.

#include <iostream>
#include <string>	// libraries used in the program
using namespace std;

int main( )
{
	//Display title and skip a line
	cout << "GPA CALCULATOR" << endl;
	cout << endl;

	//variables used
	string name;
	string level;
	string department;

	//int totalUnits;
	//int totalGradePoints;


	//Output for student name and accept name as string
	cout << "Student name:";
	// get the whole line in case the user inputs his/her full name
	getline (cin, name);
	//Output for student level and accept level as string and skip a line
	cout << "Student level:";
	cin	 >> level;
	//begin the department department loop
	do	
	{
		cout << endl;
		cout << "Course department:";
		cin >> department;
		cout << endl;
		cout << " loop" << endl;
	}while (department != "");
	
	cout << "dead loop";
	return 0;
}

What are you doing to try and end the loop?

What are you doing to try and end the loop?

Sorry if this is a dumb question, isn't the test suppose to end the loop? Is there something i'm suppose to add inside the loop to end? Professor said not to use break, so i just assumed that if the test "department != "" " wasn't met the loop would you just end. Thank you in advance.

When is department == "" ? Are you sure?

If tests don't work, you need to verify the variable values. Output them, or use the debugger.

Sorry if this is a dumb question, isn't the test suppose to end the loop? Is there something i'm suppose to add inside the loop to end? Professor said not to use break, so i just assumed that if the test "department != "" " wasn't met the loop would you just end. Thank you in advance.

Sorry, I should have been more clear, What I meant was, You take input everytime the loop runs. The loop will only exit once that input satisfies a certain expression. So, what are you inputting to satisfy

while(department!="")

As WaltP pointed out, is department ever = "" ? When?

Sorry, I should have been more clear, What I meant was, You take input everytime the loop runs. The loop will only exit once that input satisfies a certain expression. So, what are you inputting to satisfy

while(department!="")

As WaltP pointed out, is department ever = "" ? When?

Yes sorry for not being more specific, professor wants a program that asks a series of questions as long as the department equals something (as long as the user doesn't enter <return>). Thanks for all your help, I figured it out though. It had to do with using cin instead of getline (cin would store the empty space).

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.