delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/28/10:35:16

Message-ID: <377787DA.F805B77@calderathin.com>
Date: Mon, 28 Jun 1999 08:34:02 -0600
From: Jared Stevens <stevja AT calderathin DOT com>
X-Mailer: Mozilla 4.6 [en] (Win95; I)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: I HAVE A PARSE ERROR AND I CAN"T FIX IT!!!
References: <iFtd3.11225$5i7 DOT 7064 AT news DOT rdc1 DOT va DOT home DOT com>
Reply-To: djgpp AT delorie DOT com

This is a multi-part message in MIME format.
--------------F1A724A9595CAA8B6752CBFB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

K... I've gone through your program and fixed some stuff... I commented
on the lines that have problems and then compiled it with a c++
compiler. (DJGPP: gxx 4_function_calc.cc -o fun.exe -lm) and it worked
fine. 

Gregory Akselrod wrote:
> 
> I have an error and I can't seem to resolve it. Attached to this e-mail is
> the source code to my code. Every time I try to compile it I get an error:
> 
> 4_function_calc.cc:48: parse error before `else'
> 
> I've tried so many things to fix it. I'm just a newbie so this is probably
> very simple to fix. Please tell me what's wrong and if you would be so kind
> edit the source code so I can see what's wrong. Thankyou.
> 
> -Greg Akselrod
> 
>                          Name: 4_function_calc.cc
>    4_function_calc.cc    Type: unspecified type (application/octet-stream)
>                      Encoding: x-uuencode
--------------F1A724A9595CAA8B6752CBFB
Content-Type: text/plain; charset=us-ascii;
 name="4_function_calc.cc"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="4_function_calc.cc"

#include <iostream.h>

int subtract(int topNumber, int bottomNumber);
int multiply(int factor1, int factor2);
int Divide(int dividend, int divisor);
int Remainder(int dividend1, int divisor1);

 int addend1;
 int addend2;
 int sum;
 int difference;
 int bottomNumber;
 int topNumber;
 bool Wdivide;
 bool Wadd;
 bool Wsubtract;
 bool Wmultiply;
 int dividend;
 int divisor;
 int quotient;
 int divisor1;
 int dividend1;
 int remainder; 

int main()
{
 int factor1=0; // The vars declares should be here
 int factor2=0;
 int product=0; // You may also wish to initialize them with zero, (they can start off with any number in them)

 cout << "Would you like to divide? 0-no, 1-yes: ";
 cin >> Wdivide;
 if (Wdivide == 1) //; You don't want ';' after if statements... otherwise the compiler thinks that is all and wonders what the heck all the bracket stuff is for
  
{ 
   cout << "Please enter the dividend: ";
   cin >> dividend;
   cout << "\nPlease enter the divisor: ";
   cin >> divisor;
   quotient = Divide(dividend, divisor);
   divisor1 = divisor;
   dividend = dividend;  
   remainder = Remainder(dividend1, divisor1);
   cout << "\nThe answer is: ";
   cout << quotient;
   cout << " with a remainder of: ";
   cout << remainder << endl;
} // end of if
else
{ // you may want an open bracket on this else call because you have multiple lines here
cout << "Would you like to multiply? 0-no, 1-yes: ";
cin >> Wmultiply;
if (Wmultiply == 1) //; same thing here

 /*int factor1; // this feature (declaring variables in the middle of a function) is not supported in 'C'. You need to use C++, or declare them at the top of a function
 int factor2;
 int product; */
/* Line 50 */ cout << "Please enter your first factor: ";
cin >> factor1;
cout << "\nPlease enter your second factor: ";
cin >> factor2;
product = multiply(factor1, factor2);
cout << "\nThe answer is: ";
cout << product << endl;
} // end of else
} // you dont need ';' on brackets unless using structures or classes (end of main)

int Divide(int divi, int divis)
{
int quotient;
return (quotient = divi / divis);
} // not even on functions;


int Remainder(int dividend1, int divisor1)
{
int remainder;  /* Line 70 */
remainder = dividend1 % divisor1;
return remainder;
} // this function was done correctly

int multiply(int factor1, int factor2)
{
int product;
return product = (factor1 * factor2);
} // no semi-colon;

--------------F1A724A9595CAA8B6752CBFB--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019