Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,973 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,397 people online right now. Registration is fast and FREE... Join Now!




I'm stocked

 
Reply to this topicStart new topic

I'm stocked, Assignment

Elegy
3 Dec, 2007 - 11:43 PM
Post #1

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 4


My Contributions
Hello,
I have an assignment, which is almost done, but I'm completely stocked on one little thing.

this is what i need to do:

The program shuld take from the user the class/subject names and for each class, the number
of hours, a student has to attend in one week, together with the number of hours, the student
has missed for each class. The program should then display a nicely laid out table of the classes
with their related number of hours and the missed number of hours. The program should also tell
the user, how many hours she/he has to perform self-study for each subject/class and the total
hours of his/her needed for self-study for that week to catch up with her/his studies, with the
idea in mind, that each missed class hour is equal to two hours of self study.
Assumptions: a student doesn't have the same class twice a week; a student has a minimum of 3 classes in a week;

And that's what I have:

CODE

#include<iostream.h>
#include <stdio.h>
#include <cstring.h>

int main()
{
unsigned int i,j,amount_classes, hours[10], missed[10], self_study[20];
unsigned int self_total;
char str[70][40], name[40];
cout<<"Please enter your name: "<<endl;
gets(name);
cout<<"Please enter how many classes you have per week: "<<endl;
cin>>amount_classes;
if (amount_classes<3)
    {
    cout<<"You can't have less than 3 classes a week!";
    return 0;
    }
else
{
for (i=1; i<=amount_classes; i++)
{
    cout<<"Please enter the name of "<<i<<" subject: "<<endl;
    gets(str[i]);
        for (j=1;j<=i-1;j++)
            if (!strcmp(str[i],str[j]))
            {cout<<"You've entered same subject twice!"<<endl;
            return 0;
            }
    cout<<"How many hours per week do you have for this class? "<<endl;
    {cin>>hours[i];
        if (hours[i]>168)
        {cout<<"This is impossible! There is 168 hours in a week! "; return 0;}}
    cout<<"And how many did you miss this week? :"<<endl;
    cin>>missed[i];
    self_study[i]=missed[i]*2;
    if (missed>hours)
    {cout<<"You can't miss more hours than it should be per week!";
     return 0;
    }
    }
self_total=0;
for (i=1;i<=amount_classes;i++)
    self_total=self_total+self_study[i];

for (i=1;i<=amount_classes;i++)
{
cout<<strlen(str[i])<<endl;
for (j=strlen(str[i]);j<25;j++)
     str[i][j]='*';
    }

  for (i=0; name[i]; i++)
name[i]=toupper(name[i]);
cout<<endl<<name<<": "<<endl;


for (i=1;i<=amount_classes; i++)
{
    cout<<endl<<str[i]<<hours[i];
    if (hours[i]>=10)
       cout<<"*****"<<missed[i];
    else
       cout<<"******"<<missed[i];
    cout<<"______"<<self_study[i]<<"  ";
   cout<<strlen(str[i]);
   }
cout<<"\nTotally this week you need to study "<<self_total<<" hours."<<endl;
}
cin.get();
cin.get();
}


The problem is when i'm trying to do thos table, it gives me some strange symbols at the end, and the length of a string is bigger than it should be. Whan i change it, it still gives me different kind of results, with this strange symbols.

Mod Edit: Please use code tags: code.gif

To use them properly you would type something like:
[code]
//Your code goes here
#include <stdio.h>

int main() {
printf("Hello World");
return 0;
}
[/code]
User is offlineProfile CardPM
+Quote Post

Elegy
RE: I'm Stocked
4 Dec, 2007 - 03:54 PM
Post #2

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 4


My Contributions
ok, sorry, I will.

I think it works now biggrin.gif
I just changed the size of array char for str[50][50]
I still don't understand why it makes this differense, but it did work.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 06:38PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month