Thread: loop not working

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    loop not working

    why is this loop not working?


    Code:
    	
    cout << "\nEnter first student?\nEnter Y or N\n";
    	cin.getline(response, 8);
    	cin.ignore(80, '\n');
    
    	while (toupper(*response) == 'Y')
    	{
    		for(row=0;row<TABLE_SIZE;++row)
    		{
    			while (toupper(*response) == 'Y')
    			{
    				user_prompt(main_struct[row]);
    	
    				cout << "Enter another student?\nEnter Y or N\n\n";
    				cin.getline(response, 8);
    				cin.ignore(80, '\n');
    				cout << *(main_struct[1]).phone;
    			}
    		
    			
    		}
    	}
    cout << "\aBIOTCH";

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    What's not working? You have to tell us more.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Is there a difference between ++row and row++?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    In this case, no.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    AAAHAHHHHH!!!!!!!!

    Code:
    #include <iostream.h>
    #include <iomanip.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    #define TABLE_SIZE 25
    
    struct STUDENT_STRUCT
    	{
    		char last_name [21];
    		char first_name [21];
    		char social [12];
    		char phone [9];
    		int quiz [5];
    		int final;
    		int final_grade;
    	};
    
    void			user_prompt		(STUDENT_STRUCT&);
    double			grade_computer	(STUDENT_STRUCT*);
    double			quiz_computer	(STUDENT_STRUCT*);
    
    
    int main ()
    {
    	
    	
    	STUDENT_STRUCT	main_struct[TABLE_SIZE];
    	int row = 0;
    	int count = 1;
    	char response[8];
    	int quiz_average;
    	
    
    
    	cout << "Welcome, Dr. Jacobs, to the marketing\n 101 grade";
    	cout << "computation program.\n";
    	
    	cout << "\nEnter first student?\nEnter Y or N\n";
    	cin.getline(response, 8);
    	cin.ignore(80, '\n');
    
    	while (toupper(*response) == 'Y')
    	{
    		for(row=0;row<TABLE_SIZE;++row)
    		{
    			while (toupper(*response) == 'Y')
    			{
    				user_prompt(main_struct[row]);
    	
    				cout << "Enter another student?\nEnter Y or N\n\n";
    				cin.getline(response, 8);
    				cin.ignore(80, '\n');
    				cout << *(main_struct[1]).phone;
    			}
    		
    			
    		}
    	}
    		
    	cout << "Final student class averages are as follows: \n\n";
    	row = 0;
    	
    	main_struct[row].final_grade = grade_computer(&main_struct[row]);
    	quiz_average = quiz_computer(&main_struct[row]);
    
    	cout << "HEY!!!!";
    	cout << main_struct[1].last_name;
    	cin.get();
    
    
    	return 0;
    }
    
    void user_prompt (STUDENT_STRUCT& stud_struc)
    {
    	int y;
    
    
    			cout << "\nEnter student's last name: ";
    			cin.getline (stud_struc.last_name, 21);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's first name: ";
    			cin.getline (stud_struc.first_name, 21);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's social security number: ";
    			cin.getline (stud_struc.social, 20);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's phone number: ";
    			cin.getline (stud_struc.phone, 13);
    			cin.ignore (80, '\n');
    				for (y=0;y<5;++y)
    				{
    					cout << "\nEnter student's grade for quiz " << y+1 << ": ";
    					cin >> stud_struc.quiz[y];
    				}
    			cout << "\nEnter the student's final exam grade: ";
    			cin >> stud_struc.final;
    			cout << stud_struc.last_name;
    		
    
    
    
    }
    this section of the program will NOT run correctly, compiles fine....I REALLY need help with this, im freaking out
    cout << "\aBIOTCH";

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You have to be more specific than 'its not working', or 'it doesn't run correctly'. Tell us how it is supposed to work, and what it is/isn't doing.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    how bout your other 2 functions so we can compile the program

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    ok, here it is

    problem:

    a professor of marketing keeps the following info on each studen in her marketing 101 class: student last name, student first name, ssn, phone numb, grades for 5 quizzes, grade for the final exam, and the final grade average.

    a. design a structure that will store the info on a student.

    b. write a function that prompts the user for all the info for one student except the final grade. the function's only argument should be a pointer to a structure of the type defined in part a.

    c. write a function whose only agument is a ointer to a structure of the type defined in part a and wich computes the final grade of the sudent as follows: the final grade is 75 percent of the quiz average plus 25 percent of the final exam.

    d. write a program that prompts the user to input data on as many as 25 students, which should be stored in a atable. The program should use the function of part c to compute the final grade average of each student. Finally, the program should display the quiz average, the final exam grade, and the final quiz average.


    it's not done yet, but
    this is what i have so far, i'm having trouble getting the user_prompt function to work properly, it seems to crash my compiler after the first iteration every time (after i enter Y to iterate the entries again.):

    Code:
    //schupro3.cpp
    
    /*this program computes a final average for marketing students
    using structures, pointers, and functions.*/
    
    #include <iostream.h>
    #include <iomanip.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    #define TABLE_SIZE 25
    
    struct STUDENT_STRUCT
    	{
    		char last_name [21];
    		char first_name [21];
    		char social [20];
    		char phone [13];
    		int quiz [5];
    		int final;
    		int final_grade;
    	};
    
    void			user_prompt		(STUDENT_STRUCT&);
    double			grade_computer	(STUDENT_STRUCT&);
    double			quiz_computer	(STUDENT_STRUCT&);
    
    
    
    
    
    
    
    int main ()
    {
    	
    	
    	STUDENT_STRUCT	main_struct[TABLE_SIZE];
    	int row = 0;
    	int count = 1;
    	char response[8];
    	int quiz_average;
    	
    
    
    	cout << "Welcome, Dr. Jacobs, to the marketing\n 101 grade";
    	cout << "computation program.\n";
    	
    	cout << "\nEnter first student?\nEnter Y or N\n";
    	cin.getline(response, 8);
    	cin.ignore(80, '\n');
    
    	while (toupper(*response) == 'Y')
    	{
    		for(row=0;row<TABLE_SIZE;++row)
    		{
    			while (toupper(*response) == 'Y')
    			{
    				user_prompt(main_struct[row]);
    	
    				cout << "main_struct first name  is" << main_struct[0].first_name;
    
    				cout << "Enter another student?\nEnter Y or N\n\n";
    				
    				cin.getline(response, 8);
    				
    				cin.ignore(80, '\n');
    			
    			}
    		
    			
    		}
    	}
    		
    	cout << "Final student class averages are as follows: \n\n";
    	row = 0;
    	
    	main_struct[row].final_grade = grade_computer(&main_struct[row]);
    	quiz_average = quiz_computer(&main_struct[row]);
    
    	cout << main_struct[1].last_name;
    	cin.get();
    	return 0;
    }
    
    
    
    
    
    
    
    
    void user_prompt (STUDENT_STRUCT& stud_struc)
    {
    	int y;
    
    
    			cout << "\nEnter student's last name: ";
    			cin.getline (stud_struc.last_name, 21);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's first name: ";
    			cin.getline (stud_struc.first_name, 21);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's social security number: ";
    			cin.getline (stud_struc.social, 20);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's phone number: ";
    			cin.getline (stud_struc.phone, 13);
    			cin.ignore (80, '\n');
    				for (y=0;y<5;++y)
    				{
    					cout << "\nEnter student's grade for quiz " << y+1 << ": ";
    					cin >> stud_struc.quiz[y];
    				}
    			cout << "\nEnter the student's final exam grade: ";
    			cin >> stud_struc.final;
    			cout << stud_struc.last_name;
    }
    
    
    
    
    
    double grade_computer (STUDENT_STRUCT& stud_struc)
    {
    	
    
    	int quiz_ave[TABLE_SIZE],
    		quiz_total[TABLE_SIZE],
    		q,
    		row;
    	
    	double final_ave[TABLE_SIZE];
    
    	for (row=0;row<TABLE_SIZE;++row);
    	{
    		for (q=0;q<5;++q)
    		{
    			quiz_total[row] += stud_struc[row].quiz[q];
    		}
    		
    		quiz_ave[row]= quiz_total[row]/(q+1);
    		final_ave[row] = ((.75)*(quiz_ave[row])) + ((.25)*(stud_struc[row].final));
    	}
    
    		return final_ave[TABLE_SIZE];
    }
    
    
    
    
    
    double quiz_computer (STUDENT_STRUCT* stud_struc)
    {
    	
    
    	int qquiz_ave[TABLE_SIZE],
    		qquiz_total[TABLE_SIZE],
    		row,
    		qq;
    
    	for (row=0;row<TABLE_SIZE;++row)
    	{
    
    
    		for (qq=0;qq<5;++qq)
    			qquiz_total[row] += stud_struc[row].quiz[qq];
    
    	
    	
    		qquiz_ave[row] = qquiz_total[row]/(qq+1);
    	}
    
    	return qquiz_ave[TABLE_SIZE];
    }
    cout << "\aBIOTCH";

  9. #9
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    This compiles? It spits out a sh!tload of errors for me.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    27
    yeah compiles in microsoft visual c++ 6.0 standard
    cout << "\aBIOTCH";

  11. #11
    Registered User
    Join Date
    Apr 2003
    Posts
    27
    hrmm never mind im getting 6 errors now

    i'll fix it, but i gotta eat right quick, brb in a few

    btw, x, do you post on amdmb.com?? thought i recognized the name
    cout << "\aBIOTCH";

  12. #12
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>btw, x, do you post on amdmb.com?? thought i recognized the name

    Nope. Never heard of the site even.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  13. #13
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    compute grades

    ok, my brain is fried and i'm frustrated as hell
    does anyone have any suggestions at all on how i can fix this mess?

    Code:
    /*this program computes a final average for marketing students
    using structures, pointers, and functions.*/
    
    #include <iostream.h>
    #include <iomanip.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    #define TABLE_SIZE 25
    
    struct STUDENT_STRUCT
    	{
    		char last_name [21];
    		char first_name [21];
    		char social [20];
    		char phone [13];
    		int quiz [5];
    		int final;
    		int final_grade;
    	};
    
    void			user_prompt		(STUDENT_STRUCT&);
    void			display_table	(STUDENT_STRUCT[], int, double[]);
    double&			compute_grades	(STUDENT_STRUCT&);
    
    
    int main ()
    {
    	
    	
    	STUDENT_STRUCT	main_struct[TABLE_SIZE];
    	int row = 0;
    	int count = 1;
    	char response[8];
    	
    	
    
    
    	cout << "Welcome, Dr. Jacobs, to the marketing\n 101 grade";
    	cout << "computation program.\n";
    	
    	cout << "\nEnter first student?\nEnter Y or N\n";
    	cin.getline(response, 8);
    	cin.ignore(80, '\n');
    
    	while (toupper(*response) == 'Y')
    	{
    		for(row=0;row<TABLE_SIZE;++row)
    		{
    			while (toupper(*response) == 'Y')
    			{
    				user_prompt(main_struct[row]);
    	
    				cout << "Enter another student?\nEnter Y or N\n\n";
    				
    				cin.getline(response, 8);
    				cin.ignore(80, '\n');
    			
    			}
    		
    			
    		}
    	}
    	main_struct[row].final = *(compute_grades(main_struct[TABLE_SIZE]));
    
    	final_grade[row]= 
    	display_table(main_struct[TABLE_SIZE]);
    
    	return 0;
    }
    		
    
    
    
    
    
    
    
    
    void user_prompt (STUDENT_STRUCT& stud_struc)
    {
    	int y;
    
    
    			cout << "\nEnter student's last name: ";
    			cin.getline (stud_struc.last_name, 21);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's first name: ";
    			cin.getline (stud_struc.first_name, 21);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's social security number: ";
    			cin.getline (stud_struc.social, 20);
    			cin.ignore (80, '\n');
    			cout << "\nEnter student's phone number: ";
    			cin.getline (stud_struc.phone, 13);
    			cin.ignore (80, '\n');
    				for (y=0;y<5;++y)
    				{
    					cout << "\nEnter student's grade for quiz " << y+1 << ": ";
    					cin >> stud_struc.quiz[y];
    				}
    			cout << "\nEnter the student's final exam grade: ";
    			cin >> stud_struc.final;
    		
    }
    
    
    
    
    
    void display_table (STUDENT_STRUCT stud_struc[],int size, double quiz[])
    {
    	
    	int row;
    
    
    	cout << "\n\n"	<< setw(13) << "Last Name"
    					<< setw(13) << "First Name"
    					<< setw(13) << "Quiz Average"
    					<< setw(13) << "Final Exam"
    					<< setw(13) << "Final Grade";
    				
    
    	for (row=0;row<TABLE_SIZE;++row)
    		cout	<< "\n" << setw(13) << stud_struc[row].last_name
    				<< setw(13) << stud_struc[row].first_name
    				<< setw(13) << quiz[row]
    				<< setw(13) << stud_struc[row].final
    				<< setw(13) << stud_struc[row].final_grade;
    
    }
    
    
    
    
    double& compute_grades	(STUDENT_STRUCT& stud_table)
    {
    	int row,
    		q;
    	double	quiz_total[TABLE_SIZE],
    			quiz_average[TABLE_SIZE],
    			grade[TABLE_SIZE];
    
    	
    	for (row=0;row<TABLE_SIZE;++row)
    	{
    		for (q=0;q<5;++q)
    		{
    			quiz_total[row] += stud_table[row].quiz[q];
    		}
    	}
    
    
    	for (row=0;row<TABLE_SIZE;++row)
    	{
    		quiz_average[row] = quiz_total[row]/5;
    		grade[row] = ((.75 * quiz_average[row]) + (.25 * stud_table[row].final[row]));
    	}
    
    	return &grade;
    }
    cout << "\aBIOTCH";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "try again" loop not working
    By scwizzo in forum Game Programming
    Replies: 5
    Last Post: 04-01-2007, 09:56 PM
  2. my do while loop not working
    By rodrigorules in forum C Programming
    Replies: 12
    Last Post: 09-07-2005, 06:52 PM
  3. Replies: 6
    Last Post: 07-19-2005, 01:03 PM
  4. EOF not working in a loop
    By Malabux in forum C++ Programming
    Replies: 3
    Last Post: 10-12-2003, 06:28 PM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM