Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Problems with program
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aliveiswell




PostPosted: Tue Dec 16, 2003 11:04 pm   Post subject: Problems with program

We were doing this in class in Turing and I wanted to try it in C++ but it has a lot of problems and I can't figure any of them out. They may be stupid...:
#include<iostream.h>

int numberMarks;
int counter;
int counter2;

void main()
{
// Description of program
cout << "This program will take marks from a report card and output them." << endl;
cout << "How many marks are you going to input: ";
cin >> numberMarks;

// Declare arrays for for loop
char subject[numberMarks];
int mark[numberMarks];
int perfectMark[numberMarks];

// For loop - asks for subject and marks
for (counter=0; counter<numberMarks; counter+1)
{
cout << "What subject is this mark for?";
cin >> subject[counter];
cout << "What mark did you get?";
cin >> mark[counter];
cout << "What is the mark out of?";
cin >> perfectMark[counter];
}
cout << "Your marks:" << endl;

// For loop - outputs all marks
for (counter=0; counter<numberMarks; counter+1)
{
cout << "Subject: " << subject[counter2] << endl;
cout << "Mark: " << mark[numberMarks] << "/" << perfectMark[numberMarks] << endl;
}
return 0;
}

I was using vc++
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Dec 16, 2003 11:19 pm   Post subject: (No subject)

isn't it counter++, not counter+1 Thinking
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
wtd




PostPosted: Mon Feb 09, 2004 1:39 pm   Post subject: (No subject)

Just because I'm bored...

code:
#include <iostream>
#include <vector>
#include <string>

class grade
{
   public:

   int actual, max;
   std::string subject;

   grade(int actual_grade = 0, int max_grade = 0, std::string init_subject = "")
   : actual(actual_grade)
   , max(max_grade)
   , subject(init_subject)
   { }

   void read(std::istream& in, std::ostream& out)
   {
      out << "What subject is this mark for?";
      in >> subject;
      out << "What mark did you get?";
      in >> actual;
      out << "What is the mark out of?";
      in >> max;
   }

   float percentage() const
   {
      return static_cast<float>(actual) / static_cast<float>(max);
   }

   friend std::ostream& operator<<(std::ostream& out, grade& g)
   {
      return out << "Subject: " << g.subject << std::endl
         << "Mark: " << g.actual << " / " << g.max;
   }
};

class report_card : public std::vector<grade>
{
   protected:

   int num_grades;

   public:

   report_card(int init_num_grades = 0)
   : std::vector<grade>()
   , num_grades(init_num_grades)
   {
      for (int i = 0; i < num_grades; i++)
         push_back(grade());
   }
};

int main(int argc, char ** argv)
{
   report_card rc;
   int num_grades;

    std::cout << "This program will take marks from a report card and output them." << std::endl;

   std::cout << "Enter the number of grades you'd like to input: ";
   std::cin >> num_grades;

   rc = report_card(num_grades);

   for (report_card::iterator iter = rc.begin(); iter != rc.end(); iter++)
      iter->read(std::cin, std::cout);

   std::cout << "Your marks:" << std::endl;
   for (report_card::iterator iter = rc.begin(); iter != rc.end(); iter++)
      std::cout << *iter << std::endl;

   return 0;
}
Andy




PostPosted: Mon Feb 09, 2004 5:00 pm   Post subject: (No subject)

ya u have to do counter+=1 or counter++
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: