C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 8th, 2003, 11:54 PM
magdaolsen magdaolsen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: New York
Posts: 8 magdaolsen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
String arrays + functions

I'm trying to pass a string array to a function which would populate it. Doesn't work the way I have it written below. I get a an error messages: 'string' : undeclared identifier.
PHP Code:
//Processor section
#include <iostream>
#include <string>
const int SIZE 35;        //Max number of students in class
int NumStudents;

//Function prototypes
void DisplayProgramInfo (void);
void NumOfStudents ();
void StudentData(string StudentName[], int StudentID[], double FinalGrade[]);
void ExamWeights (double Exam1Percentdouble Exam2Percentdouble Exam3Percentdouble Exam4Percent);

using namespace std;


void main (void)
{
    
//Declare variables
                                    //Number of students in class
    
int StudentID[SIZE];
    
string StudentName[SIZE];
    
double FinalGrade[SIZE];

    
//Display general info about the program
    
DisplayProgramInfo();

    
//Get number of students in class
    
NumOfStudents();
    
    
//Get Student data
    
StudentData(StudentNameStudentIDFinalGrade);

}

void DisplayProgramInfo (void)

{
    
//Display general info about the program


    
cout <<"This program will help you calculate the final grade of each student,\n"
         
<<"based on the average of 4 exam grades. It will also display the class average,\n"
         
<<"and the max and min grades for the class.\n"
         
<<"You can enter data for a maximum of 35 students.\n";
}

void NumOfStudents ()
{
    
//Get number of students in class 

    
do {
    
cout <<"\nHow many students are in the class?\t";
    
cin >> NumStudents;

    if (
NumStudents SIZE || NumStudents <= 0)
    
cout <<"\nYou have entred an incorrect number, please try again";

    } while (
NumStudents SIZE || NumStudents <= 0);
}


void StudentData(string StudentName[], int StudentID[], double FinalGrade[])
{
    
//Declare variables
    
int i(0);
//    string StudentName[SIZE];
    
double exam1exam2exam3exam4;

    
double Exam1Percent(0.0), Exam2Percent(0.0);        //Exam percentage weight 
    
double Exam3Percent(0.0), Exam4Percent(0.0);        //Exam percentage weight

    
cout << NumStudents;
    
//Get exam weights
    
ExamWeights (Exam1PercentExam2PercentExam3PercentExam4Percent);


    
//Get data

    
for (i=0NumStudentsi++)
    {
    
cout <<"\n\nPlease enter the student name: ";
    
cin >> StudentName[i];
    
cout <<"Please enter the ID number for " << StudentName[i] <<":\t";
    
cin >> StudentID[i];

    
cout <<"\nPlease enter the grade for the 1st exam:\t";
    
cin >> exam1;
    
    
cout <<"Please enter the grade for the 2nd exam:\t";
    
cin >> exam2;
    
    
cout <<"Please enter the grade for the 3rd exam:\t";
    
cin >> exam3;
    
    
cout <<"Please enter the grade for the 4th exam:\t";
    
cin >> exam4;
    
    
FinalGrade[i] = ((exam1*Exam1Percent) + (exam2*Exam2Percent) + (exam3*Exam3Percent) + (exam4*Exam4Percent));
    }



Reply With Quote
  #2  
Old April 9th, 2003, 01:47 AM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,327 7stud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 50 sec
Reputation Power: 9
In the future, please put a comment in your code on the line with the errror, so people trying to help you know where the error is.

In your program, string is not recognized because only std::string exists as an identifier. I do this after the includes:

using namespace std;

Some people say that's bad form and you should only identify the functions you are going to use in the using statements like this:

using std::cout;
using std::cin;
using std::string;

but that's way too much typing for me.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > String arrays + functions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway