-
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;
}
}
}
-
What's not working? You have to tell us more.
-
Is there a difference between ++row and row++?
-
-
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
-
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.
-
how bout your other 2 functions so we can compile the program :o
-
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];
}
-
This compiles? It spits out a sh!tload of errors for me.
-
yeah compiles in microsoft visual c++ 6.0 standard
-
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
-
>>btw, x, do you post on amdmb.com?? thought i recognized the name
Nope. Never heard of the site even.
-
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;
}