| | |
problems w/ program involving structures and arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 1
Reputation:
Solved Threads: 0
hi, i'm working on an assignment for school, and i'm having a lot of problems when i try to compile it. one of the errors is about changing the functions into arrays and getting an error about pointers, and another is trying to get the right info to the right place. i know its kind of long, but if you could help me, i'd be very grateful.
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; struct Student { char name [51]; int hwScore[6]; int midterm; int exam; }; void input(Student& student); double score (Student student); void display (Student student[], double total[]); int minIndex (double totalScore[], int size, int startIndex); void swap(double totalScore[], int i, int j); void swap2(Student student[], int i, int j); void sort (double totalScore[], int size, Student student[]); int main(){ double totalScore [100]; char again; Student student[100]; int i = 0; do { input (student[i]); totalScore[i] = score(student[i]); cout << student[i].name << "'s final score is : "; cout << totalScore[i] << endl; cout << "Enter more students? (Y or N): "; cin >> again; cout << endl; i++; cin.ignore (1, '/n'); }while (again == 'y' || again == 'Y'); sort(totalScore[], 100, student[]); for (int i = 0; i < 100; i++) display(student, totalScore[i]); return 0; } void input (Student& student) { cout << "Enter student name: "; cin.getline (student.name, 51); cout << endl; for (int i=0; i < 6; i++) { int hwNum = i; cout << "Enter hw " << hwNum + 1 << "(max 10): "; cin >> student.hwScore[i]; while ((student.hwScore[i] > 10) || (student.hwScore[i] < 0)) { cout << "Invalid input, please enter a number from 0 to 10:" << endl; cin >> student.hwScore[i]; } } cout << "Enter midterm score(max 40): "; cin >> student.midterm; while ((student.midterm > 40) || (student.midterm < 0)) { cout << "Invalid input, please enter a number from 0 to 40:" << endl; cin >> student.midterm; } cout << "Enter final score(max 100): "; cin >> student.exam; while ((student.exam > 100) || (student.exam < 0)) { cout << "Invalid input, please enter a number from 0 to 10:" << endl; cin >> student.exam; } } double score (Student student) { double totalScore = 0; double totalHw =0; for (int i=0; i < 6; i++) totalHw += student.hwScore[i]; totalScore =((totalHw/60 * 30) + (student.midterm/40 * 25) + (student.exam/100 * 45)); return totalScore; } void display (Student student[], double total[]) { int i; cout << student[i].name << endl; cout << total[i]; } int minIndex (double totalScore[], int size, int startIndex) { double min = totalScore[startIndex]; int minInd = startIndex; for (int i = startIndex + 1; i < size; i++) { if (min > totalScore[i]){ minInd = i; min = totalScore[i]; } } return minInd; } void swap(double totalScore[], int i, int j) { double temp = totalScore[i]; totalScore[i] = totalScore[j]; totalScore[j] = temp; } void swap2(Student student[], int i, int j) { Student temp = student[i]; student[i] = student[j]; student[j] = temp; } void sort (double totalScore[], int size, Student student[]) { for (int i = 0; i < size; i++) { int minInd = minIndex (totalScore, size, i); swap (totalScore[i], totalScore[minInd]); swap2 (student[i], student[minInd]); } }
sort(totalScore[], 100, student[]);
display(student, totalScore[i]); C++ Syntax (Toggle Plain Text)
int i; cout << student[i].name << endl;
C++ Syntax (Toggle Plain Text)
void swap(double totalScore[], int i, int j) void swap2(Student student[], int i, int j) swap (totalScore[i], totalScore[minInd]); swap2 (student[i], student[minInd]);
![]() |
Similar Threads
- structures, arrays, and loops? help! (C++)
- structures, arrays, pointers?!?!help! (C++)
- problems with a C++ program can't seem to compile it (C++)
- Problems with my c++ program (C++)
- Having Few Problems!! With this program?? (C)
- dynamic array of structures problem (C++)
- help regarding 2d arrays (C++)
Other Threads in the C++ Forum
- Previous Thread: octal conversion
- Next Thread: Merging two lists (STL)
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






