7 Replies - 1329 Views - Last Post: 07 December 2008 - 09:08 AM Rate Topic: -----

#1 chazhill   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-November 08

Help with code errors

Post icon  Posted 17 November 2008 - 03:21 PM

//T3 App.cpp - calculates and displays required number of single rolls of wallpaper
// Charles Hill
// Nov 16 2008
#include <iostream>
using namespace std;
int  main()
}


	//declare variables
	float  length 		=  0.0;
	float  width		  =  0.0;
	float  height 		=  0 .0;
	float  rollCoverage =  0 . 0;
	float  perimeter 	=  0 . 0;
	float  area			=  0 . 0;
	float  rolls		=  0 . 0;

	//enter input items
	cout  << "Enter room length : ";
	cin  >>  length;
	cout  <<  "Enter room width : ";
	cin  >>  width; 
	cout  <<  "Enter ceiling height : ";
	cin  >>  height;
	cout  <<  "Enter single room coverage : ";
	cin  >>  rollCoverage;

	//calculate perimeter, area, and number of single rolls. 
	perimeter = (length + width)  * 2;
	area = perimeter * height;
	rolls = area / rollCoverage;
	

	//display output item
	cout << "Single rolls :  "  << rolls << endl;

	return 0;	
	//end of main function 


I have problems compiling this and i get several errors
including 2143, 2059, 2228, 2018,
please help

Charles Hill

Is This A Good Question/Topic? 0
  • +

Replies To: Help with code errors

#2 Gloin   User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Help with code errors

Posted 17 November 2008 - 03:27 PM

I'm guessing the syntax error is because one } is missing (at the very end of your program) and also one is turned backward (beginning your main-function).
Was This Post Helpful? 0
  • +
  • -

#3 chazhill   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-November 08

Re: Help with code errors

Posted 17 November 2008 - 04:33 PM

Thanks I changed that but I still get the following errors


 //T3 App.cpp - calculates and displays required number of single rolls of wallpaper
// Charles Hill
// Nov 16 2008
#include <iostream>
using namespace std;
int  main()
{


	//declare variables
	float  length 		=  0.0;
	float  width		  =  0.0;
	float  height 		=  0 .0;
	float  rollCoverage =  0 . 0;
	float  perimeter 	=  0 . 0;
	float  area			=  0 . 0;
	float  rolls		=  0 . 0;

	//enter input items
	cout  << "Enter room length : ";
	cin  >>  length;
	cout  <<  "Enter room width : ";
	cin  >>  width; 
	cout  <<  "Enter ceiling height : ";
	cin  >>  height;
	cout  <<  "Enter single room coverage : ";
	cin  >>  rollCoverage;

	//calculate perimeter, area, and number of single rolls. 
	perimeter = (length + width)  * 2;
	area = perimeter * height;
	rolls = area / rollCoverage;
	

	//display output item
	cout << "Single rolls :  "  << rolls << endl;

	return 0;	
	//end of main function
}






------ Build started: Project: t3app.cpp, Configuration: Debug Win32 ------
Compiling...
T3App.cpp
d:\program files\microsoft visual studio 8\vc\t3app.cpp(13) : error C2143: syntax error : missing ';' before 'constant'
d:\program files\microsoft visual studio 8\vc\t3app.cpp(14) : error C2059: syntax error : 'constant'
d:\program files\microsoft visual studio 8\vc\t3app.cpp(15) : error C2059: syntax error : 'constant'
d:\program files\microsoft visual studio 8\vc\t3app.cpp(16) : error C2059: syntax error : 'constant'
d:\program files\microsoft visual studio 8\vc\t3app.cpp(17) : error C2059: syntax error : 'constant'
d:\program files\microsoft visual studio 8\vc\t3app.cpp(20) : error C2228: left of '.cout' must have class/struct/union
type is 'int'
Build log was saved at "file://d:\Program Files\Microsoft Visual Studio 8\VC\Debug\BuildLog.htm"
t3app.cpp - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Was This Post Helpful? 0
  • +
  • -

#4 Gloin   User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Help with code errors

Posted 17 November 2008 - 04:41 PM

float height = 0 .0;
float rollCoverage = 0 . 0;
float perimeter = 0 . 0;
float area = 0 . 0;
float rolls = 0 . 0;


Make sure the values say 0.0 without any blanks between numbers and decimal-points..
Was This Post Helpful? 0
  • +
  • -

#5 chazhill   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-November 08

Re: Help with code errors

Posted 17 November 2008 - 04:54 PM

Thanks for your help

Charles
Was This Post Helpful? 0
  • +
  • -

#6 Gloin   User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Help with code errors

Posted 17 November 2008 - 05:00 PM

no problemo!
Was This Post Helpful? 0
  • +
  • -

#7 student123   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 18-November 08

Re: Help with code errors

Posted 07 December 2008 - 06:13 AM

hey i am a student at uni doing C++ and i have an assenment to do and i am woring what i have to do it is to calclate the secounds past from 2000 1 1


i have attcehde my code to the bottom of this any help will be good


//
//
//

#include <iostream>
#include <iomanip>
using namespace std;

int year,month,day;
//these int are to find out leap years
int lpYear, Leap;
int hours, minutes, seconds;
int total_current_seconds;
int total_deadline_seconds;
int duration;
bool LeepYear(int year);




int main()

{



	do
	{
		cout << "hello this program is to find the time in secounds"<<endl;
		cout << "from 2000 1 1 gmt 00:00:00"<<endl;
		cout << "pleas  enter date" << endl;
		cout << "YY:MM:DD";
		cin >> year >> month >>day;

		cout <<  "Enter current time in  hours, minutes, and seconds: ";
		cin >> hours >> minutes >> seconds;

			//this checkes that the year is all ways above 2000.
		if (year < 2000)
		{
			cout << "pleas enter year bove 2000"<<endl;
		}
		if (hours >=24 ||  hours <0)
		{
			cout <<" enter a hour bettween 0  and 23";
		}
		if (minutes <0 || minutes >=60)
		{
			cout <<" enter a minute bettween 0 and 59";
		}
		if (seconds <0 || seconds >=60)
		{
			cout <<" enter a second bettween 0 and 59";
		}
			//this if statement checkes that the day for the slected months are no more then the days avilble.
		if (( day > 31) && (  month == 1 || month == 3 || month == 5|| month == 7|| month == 8|| month == 10 || month == 12))
		{
		 			cout << "pleas enter a  day below = 31" <<endl;
 		}



			//this checks to see if they eber the date for febuary is wrong.
 		bool LeapYear(lpYear);
		if ((year % 4==0) &&((year % 100!=0) || (year % 400==0)))
		{
				Leap = true;
		}
		else
		{
				Leap = false;
				cout << " Only 28 days in a normal year"<<endl;
		}
			//this if statement checkes that the day for the slected months are no more then the dys avilble.
		if (day >= 31 && (month == 4 || month == 6 || month == 9 || month == 11))
				{
					cout << "pleas enter a day bellow = 30"<<endl;
				}

		switch (month)
		{
			 case 1: case 3: case 5: case 7: case 8: case 10: case 12:
			 Days = 31;
			 break;

			 case 4: case 6: case 9: case 11:
			 Days = 30;	//makes shure moths are not above 12

			 break;if (month >= 13)

			 case 2 : {	if (LeepYear(lpYear))
				   		return 29;

				   		else

				   		return 28;
				   		break;
			 		  }
		}
			if (day <= 0)
		{
				cout<< "your day cant be <= to 0" <<endl;
		}
			//makes shure that moth are not = 0
		if (month <= 0)
		{
			cout<< "you have enter incoret month cant be <= to 0 "<<endl;
		}

	}
while  ((year < 2000) || (hours >=24 ||  hours <0) || (minutes <0 || minutes >=60) || (( day > 31) && (  month == 1 || month == 3 || month == 5|| month == 7|| month == 8|| month == 10 || month == 12))
		|| ((year % 4==0) &&((year % 100!=0) || (year % 400==0) || (day >= 31 && (month == 4 || month == 6 || month == 9 || month == 11)) || (month >= 13) (day <= 0) || (month <= 0))));
//do your calculations here in several blocks of horrible boolean algebra








/*
		cout << setfill('0');
		cout << "You entered "<< setw(2) << year << ":" << setw(2) << month << ":" << setw(2) << day
		<< ":"	<< setw(2) << hours << ":" << setw(2) << minutes << ":" << setw(2) << seconds<<endl;

	   duration=((((year -1)-2000) *365 *24 *60 *60) + ((month - 1) *day *24 *60 *60) + ((day - 1 ) *24 *60 *60 )+ (hours *60 *60 ) + ( minutes *60) +seconds);
	   cout << "Current time in seconds since midnight = " << duration<< endl;

*/







	return 0;
}



Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Help with code errors

Posted 07 December 2008 - 09:08 AM

Stop hijacking other threads and create your own new thread.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1