C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-02-2008, 12:03 PM   #1
Registered User
 
Join Date: Oct 2008
Posts: 1
Heeeelp

Hello
I would need help, it says right after here: XXX
that expected expression before else, but cant figure it out. Any hints? Thanks!


Code:
#include <stdio.h>

main ()

{

double totalsqft, roomsqft,ceilingsqft,length,width;
double labour, ceilingcost, totalcost;
double premiumcost,basiccost,regularcost;
int quality,ceiling;

/*Program*/

printf(">>>   Paint Cost Estimator   <<<\n");
printf("Enter length of the room:");
scanf("%lf",&length);
printf("Enter width of the room in feet:");
scanf("%lf", &width);
printf("Enter quality[Premium=1,Regular=2,Basic=3]:");
scanf("%d",&quality);

   if (quality == 1)
   {
   premiumcost=2*8*length+2*8*width*2*40/400;
   }
   if(quality==1 && ceiling==2);
   {
   premiumcost=2*8*length+2*8*width*2*40/400+width*length*20/400*2;
   }
   else  XXX
    {
    premiumcost=0;
    }

   if (quality==2)
   {
   regularcost=2*8*length+2*8*width*2*30/400;
   }
   if( quality==2 && ceiling==2);
    {
    regularcost=2*8*length+2*8*width*2*30/400+width*length*20/400*2;
    }
    else      XXXXX
    {
    regularcost=0;
    }
   if (quality==3)
   {
   basiccost=2*8*length+2*8*width*2*20/400;
   }
   if ( quality==3 && ceiling==2);
    {
    basiccost=2*8*length+2*8*width*2*20/400+width*length*20/400*2;
    }
    else     XXX
    {
    basiccost=0;
    }


printf("Enter if ceiling to be painted [Yes-1,No-2]:");
scanf("%d", &ceiling);

   if (ceiling != 1)
   {
   ceilingcost = 0;
   }
   else
   {
   ceilingcost = width*length*20/400*2;
   }

/*Calculate room squarefeet*/

roomsqft=2*8*length+2*8*width;
totalsqft=ceilingsqft+roomsqft;
labour=100+40*totalsqft/200;
totalcost=labour+basiccost+regularcost+premiumcost;
ceilingsqft=width*length;

printf("Total Area: %.2lf sqft\n",totalsqft);
printf("Premium paint cost: $ %.2lf\n", premiumcost);
printf("Regular paint cost: $ %.2lf\n", regularcost);
printf("Basic paint cost: $ %.2lf\n", basiccost);
printf("Labour costs: $ %.2lf \n", labour);
printf("TOTAL COST: $ %.2lf \n",totalcost);

}
bzs1 is offline   Reply With Quote
Old 10-02-2008, 12:08 PM   #2
Banned
 
master5001's Avatar
 
Join Date: Aug 2001
Location: Visalia, CA, USA
Posts: 3,699
Code:
if (quality == 1)
{
  premiumcost=2*8*length+2*8*width*2*40/400;
}
if(quality==1 && ceiling==2);
{
  premiumcost=2*8*length+2*8*width*2*40/400+width*length*20/400*2;
}
else  // XXX -- I give up, a rabbi?
{
 premiumcost=0;
}
Logic error? So are you intending for this to happen?
master5001 is offline   Reply With Quote
Old 10-02-2008, 12:08 PM   #3
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
First of all, http://cpwiki.sourceforge.net/Implicit_main
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 10-02-2008, 12:09 PM   #4
Registered User
 
Join Date: Sep 2008
Location: California
Posts: 17
Code:
   if ( quality==3 && ceiling==2);
    {
    basiccost=2*8*length+2*8*width*2*20/400+width*length*20/400*2;
    }
    else     XXX
    {
    basiccost=0;
    }
Did you mean to put a semicolon after that if statement? I'm pretty sure what happens is that the compiler thinks you're making a one line if statement, and thus does not associate the else with it.
Smattacus is offline   Reply With Quote
Old 10-02-2008, 12:09 PM   #5
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Right on the spot.

Code:
#include <stdio.h>

main ()
{

double totalsqft, roomsqft,ceilingsqft,length,width;
double labour, ceilingcost, totalcost;
double premiumcost,basiccost,regularcost;
int quality,ceiling;

/*Program*/

printf(">>>   Paint Cost Estimator   <<<\n");
printf("Enter length of the room:");
scanf("%lf",&length);
printf("Enter width of the room in feet:");
scanf("%lf", &width);
printf("Enter quality[Premium=1,Regular=2,Basic=3]:");
scanf("%d",&quality);

   if (quality == 1)
   {
   premiumcost=2*8*length+2*8*width*2*40/400;
   }
   if(quality==1 && ceiling==2);
   {
   premiumcost=2*8*length+2*8*width*2*40/400+width*length*20/400*2;
   }
   else  XXX // Wth???
    {
    premiumcost=0;
    }

   if (quality==2)
   {
   regularcost=2*8*length+2*8*width*2*30/400;
   }
   if( quality==2 && ceiling==2);    {
    regularcost=2*8*length+2*8*width*2*30/400+width*length*20/400*2;
    }
    else      XXXXX // Wth???
    {
    regularcost=0;
    }
   if (quality==3)
   {
   basiccost=2*8*length+2*8*width*2*20/400;
   }
   if ( quality==3 && ceiling==2);
    {
    basiccost=2*8*length+2*8*width*2*20/400+width*length*20/400*2;
    }
    else     XXX // Wth???
    {
    basiccost=0;
    }


printf("Enter if ceiling to be painted [Yes-1,No-2]:");
scanf("%d", &ceiling);

   if (ceiling != 1)
   {
   ceilingcost = 0;
   }
   else
   {
   ceilingcost = width*length*20/400*2;
   }

/*Calculate room squarefeet*/

roomsqft=2*8*length+2*8*width;
totalsqft=ceilingsqft+roomsqft;
labour=100+40*totalsqft/200;
totalcost=labour+basiccost+regularcost+premiumcost;
ceilingsqft=width*length;

printf("Total Area: %.2lf sqft\n",totalsqft);
printf("Premium paint cost: $ %.2lf\n", premiumcost);
printf("Regular paint cost: $ %.2lf\n", regularcost);
printf("Basic paint cost: $ %.2lf\n", basiccost);
printf("Labour costs: $ %.2lf \n", labour);
printf("TOTAL COST: $ %.2lf \n",totalcost);

}
Errors in red.
Furthermore, two more errors:

warning C4700: uninitialized local variable 'ceiling' used (line 25)
warning C4700: uninitialized local variable 'ceilingsqft' used (line 75)
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.

Last edited by Elysia; 10-02-2008 at 12:13 PM.
Elysia is offline   Reply With Quote
Old 10-02-2008, 12:17 PM   #6
Banned
 
master5001's Avatar
 
Join Date: Aug 2001
Location: Visalia, CA, USA
Posts: 3,699
Besides what I had bolded and was reaffirmed by the masses, look at the actual if statements too. I mean read them and think about what you are saying?

Are you doing something more than once? Would more work being done redundantly mean that your computer is wasting its time?
master5001 is offline   Reply With Quote
Reply

Tags
else problems, if else, if if else

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Heeeelp! jaredcamel C++ Programming 3 07-22-2006 03:00 PM
HEEEELP: Letters to ASCII decimal equivalents? Mazerius C++ Programming 7 10-30-2002 09:56 AM
Heeeelp.. Question... NANO C++ Programming 5 04-12-2002 06:06 PM
salary program heeeelp! pancho C Programming 6 02-02-2002 08:56 PM


All times are GMT -6. The time now is 06:53 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22