c++ schoolwork problem parse error...

Discussion in 'Software' started by ssjchris_29, Sep 6, 2004.

  1. ssjchris_29

    ssjchris_29 Private E-2

    Hello, ok, we use Sun Solaris ona main server box and telnet into it. we use the Pico editor for code and the g++ compiler program. i just started the c++ language and here's the problem i'm having. i keep getting 3 parse errors and it also says that my int main() is in error as well. here's the code and the errors. can anyone tell me what is wrong with this code? Thank You for any help!!!!!

    //Chris Ward
    //cs201 Lab1 Part3 improved

    #include <iostream>
    #include <cmath>

    using namespace std;

    int main() //Main Function
    {
    // variables for number of glasses
    int intNumMonths = 0;
    int intMonthCount = 0;
    int intNumGlasses = 0;
    int intGlassesSoldTotal = 0;
    int intCount = 0;
    int intGlassesAverage = 0;

    cout << "" << endl; //Line Break

    //Introduction
    cout << "Welcome lemonade fans! This program calculates the
    average number of glasses of lemonade that I sold during the monthly
    time period I sold it." << endl;

    cout << "" << endl; //Line Break

    //Input for length of time you sold
    lemonade

    cout << "Enter number of months you sold lemonade and press
    return: " << endl;

    cin >> intNumMonths;

    cout << "" << endl; //LineBreak

    do //Start Do Loop
    {
    cout << "Enter the Number of Glasses of Lemonade you sold during

    Month " << intMonthCount << "." << endl;
    cout << "" << endl; //LineBreak
    cin >> intNumGlasses;

    cout << "" << endl; //Line Break
    intCount + 1
    intMonthCount + 1
    intGlassesSoldtotal = intGlassesSoldTotal + intNumGlasses;
    } //End Do Loop
    while intCount < intNumMonths; //Check for the Do Loop

    intGlassesAverage = intGlassesSoldTotal / intNumMonths;

    cout << "The average number of glasses sold is: " <<
    intGlassesAverage << endl;

    return 0;
    }

    ***** and the errors i get are *****

    WardLemonade2.cpp: In function `int main()':
    WardLemonade2.cpp:31: parse error before `<'
    WardLemonade2.cpp:47: parse error before `+'
    WardLemonade2.cpp:50: parse error before `<'


    i've looked and looked at teh code and it all looks kosher to me. any ideas?

    thanks again for any help!!!!
     
  2. iamien

    iamien Cptn "Eh!"

    intCount + 1
    intMonthCount + 1
    Is missing semi colons at end of each
    Also use code tags from now on please
    Code:
    intCount + 1;
    intMonthCount + 1;
    
    Code:
    while intCount < intNumMonths;
    should be
    while (intCount < intNumMonths);
    
    I dont have a compiler handy so doing this from what i can spot
     
  3. Wookie

    Wookie Sergeant Major

    Code:
    
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main() //Main Function
    {
    // variables for number of glasses
    int intNumMonths = 0;
    int intMonthCount = 0;
    int intNumGlasses = 0;
    int intGlassesSoldTotal = 0;
    int intCount = 0;
    int intGlassesAverage = 0;
    
    cout << "" << endl; //Line Break
    
    //Introduction
    cout << "Welcome lemonade fans! This program calculates the average number of glasses of lemonade that I sold during the monthly time period I sold it." << endl;
    
    cout << "" << endl; //Line Break
    
    //Input for length of time you sold
    //lemonade
    
    cout << "Enter number of months you sold lemonade and press return: " << endl;
    
    cin >> intNumMonths;
    
    cout << "" << endl; //LineBreak
    
    do //Start Do Loop
    {
    cout << "Enter the Number of Glasses of Lemonade you sold during Month " << intMonthCount << "." << endl;
    cout << "" << endl; //LineBreak
    cin >> intNumGlasses;
    
    cout << "" << endl; //Line Break
    intCount++;
    intMonthCount++;
    intGlassesSoldTotal = (intGlassesSoldTotal + intNumGlasses);
    } //End Do Loop
    while (intCount < intNumMonths); //Check for the Do Loop
    
    intGlassesAverage = intGlassesSoldTotal / intNumMonths;
    
    cout << "The average number of glasses sold is: " <<
    intGlassesAverage << endl;
    
    return 0;
    } 
    This worked for me. Try it out. I dont know if the messageboard did it or if it was your code but when you do

    cout << "Blah Blah
    Blah";

    skipping A line like that doesnt work.


    intGlassesSoldTotal

    you have a lowercase t in your code which was causing an error also because it was declared as I just typed it.
     
  4. rmStar-R

    rmStar-R Private E-2

    To make it look better (during editing) why not try breaking the long lines into two lines of codes.

    It won't break in the output.

    Example..
    Code:
    
    cout << "veryyyyyy loooooooong
    code" << endl;
    
    
    should be encoded as:

    Code:
    
    cout << "veryyyyy looong";
    cout << " code" << endl;
    
    
    neat! :)

    further, you don't need to print "something" to break a line. just output endl.

    so,
    Code:
    
    cout << "blah blah blah" << endl << endl;
    
    
    gives one line blank.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds