»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 12-01-2003, 07:03 PM   #1 (permalink)
Registered User
 
Join Date: Dec 2003
Location: NJ
Posts: 1
insane_jester is on a distinguished road
Send a message via Yahoo to insane_jester
Systems System("pause"); not working corectly

Well i'm having a very hard time with just one simple little issue and i haven't been able to get around this problem at all..

I wrote a program where the user inputs info and then the computer prints results back to the command prompt window.. Well here is the code i hope that someone can figure this out for me.. or help me figure it out...

Two files for reference::

//file1.cpp
//List the include files
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>

//the struct that is being made is being used outside this source.. Look at the linked file strudent_record.h
#include"student_record.h"

//Define an array of student records using the Student_Record struct
struct Student_Record students[3];



//How to compute the grade and a way to find out which student you are on
void compute_grade(int j) //index was int to keep track of which student was being tested
{

float average = (students[j].labAverage + students[j].testAverage) / 2;
// give test results on what grade the student should recieve

if (average >= 89.5)
students[j].grade='A';
else if (average >= 79.5)
students[j].grade='B';
else if (average >= 69.5)
students[j].grade='C';
else if (average >= 59.5)
students[j].grade='D';
else
students[j].grade='F';
j++;
}

//Define a function to input a student record, which consists of all the elements of the Student_Record struct
//This function should take the subscript of the student array as input.

void input_record(int i)
{
cout << "\t\t\t\t--------------\n\t\t\t\t| |\n\t\t\t\t| Input Info |\n\t\t\t\t| |\n\t\t\t\t--------------\n\n\n";
cout << "\t\t\t\t Student " << i + 1 << "\n\n";
cout << "Please Enter Student's " << i + 1 << " Last Name:\n";
cin >> students[i].lastName;
cout << "\nPlease Enter Student's " << i + 1<< " First Name:\n";
cin >> students[i].firstName;
cout << "\nPlease Enter Student's " << i + 1<< " Id#:\n";
cin >> students[i].studentId;
cout << "\nPlease Enter Student's " << i + 1<< " Lab Average\n";
cin >> students[i].labAverage;
cout << "\nPlease Enter Studen's " << i + 1<< " Test Average\n";
cin >> students[i].testAverage;
system("cls");
}



void output_record(int i)
{
system("cls");
cout << "\t\t\t\t---------------\n\t\t\t\t| |\n\t\t\t\t| Report Card |\n\t\t\t\t| |\n\t\t\t\t---------------\n\n\n";
cout << "\t\t\t\t Student " << i << "\n\n";
cout << "\nLast Name: \t" << students[i].lastName;
cout << "\nFirst Name: \t" << students[i].firstName;
cout << "\nStudent ID#: \t" << students[i].studentId;
cout << "\nLab Average: \t" << students[i].labAverage;
cout << "\nTest Average: \t" << students[i].testAverage;
cout << "\nStudents Grade: \t" << students[i].grade;
system("pause") // here is where i have my problem it will pause but only after you hit it twice and it doesn't do it when it should..

//These are a few things i have tried to do to go around this problem. inputting what i just call a stepper by using an int of x and then placing in a cin > x; so that you type a key and press enter to move on.. that hasn't worked.. i have also tried to force a print before the pause.. that hadn't worked.. there has been many more things but i just can't think of what else to do to fix my problem..
}




void main(void)
{
int i;
for (i=0; i < 3; i++)
{
input_record(i);
compute_grade(i);
}

for (i=0; i < 3; i++)
{
output_record(i);

}
}


//student_record.h
//List the include files
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>



//Define structures

struct Student_Record
{
char lastName[20];
char firstName[20];
char studentId[10];
float labAverage;
float testAverage;
char grade;
};

//Define an array of student records using the Student_Record struct
extern struct Student_Record students[3];

View above for problem in output_record() within file1.cpp
Attached Images
File Type: jpg problem.jpg (53.2 KB, 48 views)

insane_jester is offline   Reply With Quote
Old 12-06-2003, 04:58 PM   #2 (permalink)
Registered User
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Champaign, IL
Posts: 3,253
jkrohn is on a distinguished road
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
You should be able to acheive this by using getch() instead of system(pause);

Jkrohn
__________________
Jkrohn
jkrohn is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 10:06 AM.