The program below compiles. The only problem I am having at them moment is the loop in the main function...
Code:
for(row=0;row<TABLE_SIZE;++row)
{
if(response = 1)
{
user_prompt(main_struct[row]);
cout << "Enter another student?\nEnter 1 for yes or 2 for no\n\n";
cin >> response;
}
else
break;
}
It doesn't want to stop when I hit a number other than 1. I've tried other types of loops as well. The choice started out as a y or n and i took the choice in as a character string and did a
Code:
while(toupper(*response) == "Y")
but that didn't work either, so i thought that using integers would for sure work, but they don't. the closest type of loop that has almost worked is a do-while loop but when i hit no it still went thru the loop one more time
again, the entire program is below if anyone wants to compile it.
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];
double quiz [5];
double final;
double final_grade;
};
void user_prompt (STUDENT_STRUCT&);
void display_table (STUDENT_STRUCT, double);
double compute_grades (STUDENT_STRUCT&);
double compute_quizes (STUDENT_STRUCT&);
int main ()
{
STUDENT_STRUCT main_struct[TABLE_SIZE] = {0};
int row = 0;
int response;
double quiz_ave[TABLE_SIZE]={0};
cout << "Welcome, Dr. Jacobs, to the marketing\n 101 grade";
cout << "computation program.\n";
for(row=0;row<TABLE_SIZE;++row)
{
if(response = 1)
{
user_prompt(main_struct[row]);
cout << "Enter another student?\nEnter 1 for yes or 2 for no\n\n";
cin >> response;
}
else
break;
}
for (row = 0; row<TABLE_SIZE; ++row)
{
main_struct[row].final_grade = compute_grades(main_struct[row]);
}
for (row = 0; row<TABLE_SIZE; ++row)
{
quiz_ave[row] = (compute_quizes(main_struct[row]))/5;
}
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)
{
display_table(main_struct[row], quiz_ave[row]);
}
cout << "\n\n\n";
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, double quiz)
{
cout << "\n" << setw(13) << stud_struc.last_name;
cout << setw(13) << stud_struc.first_name;
cout << setw(13) << quiz;
cout << setw(13) << stud_struc.final;
cout << setw(13) << stud_struc.final_grade;
}
double compute_grades (STUDENT_STRUCT& stud_table)
{
int row,
q;
double quiz_total[TABLE_SIZE]={0},
quiz_average[TABLE_SIZE]={0},
grade[TABLE_SIZE]={0};
for (row=0;row<TABLE_SIZE;++row)
{
for (q=0;q<5;++q)
{
quiz_total[row] += stud_table.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.final));
}
return (grade[TABLE_SIZE]);
}
double compute_quizes (STUDENT_STRUCT& stud_table)
{
int q,
row;
double quiz_total[TABLE_SIZE]={0};
double quiz_average[TABLE_SIZE]={0};
for (row=0;row<TABLE_SIZE;++row)
{
for (q=0;q<5;++q)
{
quiz_total[row] += stud_table.quiz[q];
}
}
for (row=0;row<TABLE_SIZE;++row)
{
quiz_average[row] = quiz_total[row]/5;
}
return (quiz_average[TABLE_SIZE]);
}