Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ help
#3
We didn't HAVE to import data for this, but I wanted to try it. This is the code I wrote without importing data.

Code:
#include <iostream>
using namespace std;
int main()
{
    char student;
    double grade;
    double femalegrades=0;
    double malegrades=0;
    int femalecount=0;
    int malecount=0;
    double femaleaverage=0;
    double maleaverage=0;

    cout<<"Enter in the gender of the student then the grade"<<endl;
    cout<<"Enter end to stop"<<endl;
    cin>>student>>grade;

    if (student == 'm')
    {
        malegrades+=grade;
        malecount++;
    }
    if (student == 'f')
    {
        femalegrades+=grade;
        femalecount++;
    }


    while (student == 'f' || student == 'm')
    {
          cin>>student>>grade;

          if (student == 'm')
          {
          malegrades+=grade;
          malecount++;
          }
          if (student == 'f')
          {
          femalegrades+=grade;
          femalecount++;
          }
    }

    maleaverage=malegrades/malecount;
    femaleaverage=femalegrades/femalecount;

    cout<<"Sum of the male grades : "<<malegrades<<endl;
    cout<<"Sum of the female grades : "<<femalegrades<<endl;
    cout<<"Male count : "<<malecount<<endl;
    cout<<"Female count : "<<femalecount<<endl;
    cout<<"Male GPA average : "<<maleaverage<<endl;
    cout<<"Female GPA average : "<<femaleaverage<<endl;

    system("pause");
    return 0;
}

runs just fine but you have to type all of the stuff manually (dunno if that's what he wanted to be honest).

and I have NO IDEA what ifstream and ofstream are lmao. I'm so noob at this ="(

This is the next assignment I'm working on now
 Spoiler

man I suck at functions too -_-"
What I think I'm going to do for the random addition problems is make a randomizer spit out 10 numbers, and store those 10 numbers into 10 variables. Then just do like number1+number2 = answer.

could someone explain how to call out random numbers from an array? That would definitely be useful

Edit- I'm having trouble getting my randomizer to give me different numbers. This is me playing around with my randomizer, but it's spitting out the same number for randnum1 and randnum2
Code:
#include <iostream>
using namespace std;
int random();
int main()
{
    int randnum1, randnum2;

    randnum1 =  random();
    randnum2 =  random();

    cout<<randnum1<<endl;
    cout<<randnum2<<endl;

    system("pause");
    return 0;
}

int random()
{
    int number;
    srand ( time(NULL) );
    number=(rand()%11);
    return (number);
}
Reply


Messages In This Thread
C++ help - by DrRusty - 2010-09-21, 10:03 AM
C++ help - by iamflip - 2010-09-21, 10:22 AM
C++ help - by DrRusty - 2010-09-21, 10:41 AM
C++ help - by Eos - 2010-09-21, 11:53 AM
C++ help - by Fiel - 2010-09-21, 12:23 PM
C++ help - by Eos - 2010-09-21, 12:34 PM
C++ help - by DrRusty - 2010-09-21, 12:42 PM
C++ help - by Eos - 2010-09-21, 12:47 PM
C++ help - by DrRusty - 2010-09-21, 12:55 PM
C++ help - by Fiel - 2010-09-21, 12:59 PM
C++ help - by Fiel - 2010-09-21, 01:21 PM
C++ help - by Stereo - 2010-09-21, 01:40 PM
C++ help - by DrRusty - 2010-09-21, 04:23 PM
C++ help - by Fiel - 2010-09-21, 04:35 PM
C++ help - by DrRusty - 2010-09-21, 05:02 PM
C++ help - by Fiel - 2010-09-21, 05:10 PM
C++ help - by DrRusty - 2010-09-21, 05:31 PM
C++ help - by GummyBear - 2010-09-22, 06:21 AM
C++ help - by DrRusty - 2010-09-22, 08:24 AM
C++ help - by GummyBear - 2010-09-22, 09:39 AM
C++ help - by Stereo - 2010-09-22, 01:41 PM
C++ help - by GummyBear - 2010-09-22, 07:15 PM
C++ help - by Fiel - 2010-09-22, 08:50 PM
C++ help - by GummyBear - 2010-09-23, 10:27 AM
C++ help - by DrRusty - 2010-09-27, 09:22 AM
C++ help - by Eos - 2010-09-27, 09:28 AM
C++ help - by DrRusty - 2010-09-27, 09:34 AM
C++ help - by Eos - 2010-09-27, 09:44 AM
C++ help - by Fiel - 2010-09-27, 10:13 AM
C++ help - by Eos - 2010-09-27, 10:27 AM
C++ help - by DrRusty - 2010-09-27, 10:28 AM
C++ help - by Eos - 2010-09-27, 10:34 AM
C++ help - by DrRusty - 2010-09-27, 11:28 AM
C++ help - by ArbalistMaster - 2010-09-27, 01:24 PM
C++ help - by Fiel - 2010-09-27, 03:44 PM
C++ help - by Stereo - 2010-09-27, 04:57 PM
C++ help - by GummyBear - 2010-09-28, 08:57 AM
C++ help - by Russt - 2010-09-28, 07:31 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)