5 Replies - 999 Views - Last Post: 23 February 2012 - 09:30 PM Rate Topic: -----

#1 Mike92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-February 12

Converting loops error c2447 / Question/problem

Posted 22 February 2012 - 09:11 PM

#include <iostream>


using namespace std;

int main ()

/*
convert the following while loop to a for loop: 
int count = 0; 
while ( count < 50) { 
   cout << " count is " << count << endl; 
   count++; 
   */
{

	int count = 0;                                   //start at 0
	for (count = 0 ; count < 50; count++)            //Goes up to 50, adds by 1 

	cout << "The count is " << count << endl;

}
/*
convert the following for loop to a while loop: 
//for ( int x = 50; x > 0; x--) {
//cout << x << " seconds to go.\ n";
*/ 

{	
	int x = 50;
	
	while ( x > 0)
	{
		cout << "seconds to go" << x <<endl;
		x--;
	}

	return 0 ;
	}


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 23 February 2012 - 04:28 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Converting loops error c2447 / Question/problem

#2 Mike92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-February 12

Re: Converting loops error c2447 / Question/problem

Posted 22 February 2012 - 09:23 PM

I suppose I am asking what is wrong with this that it will not run? I am very new to doing this.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: Converting loops error c2447 / Question/problem

Posted 23 February 2012 - 04:29 AM

Copy and paste your errors exactly as they appear in Visual Studio.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: Converting loops error c2447 / Question/problem

Posted 23 February 2012 - 07:36 AM

You seem to have mismatched braces. Count your opening braces { and your closing braces } the number should match.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 Mike92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-February 12

Re: Converting loops error c2447 / Question/problem

Posted 23 February 2012 - 06:06 PM

I cant seem to find a mismatched {, but I was also wondering if I should put this into the program so it runs both equations or will it do it automaticly?

#define pause system("pause")

then after the first block of code put this line in

pause;
Will this help the program compile?
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: Converting loops error c2447 / Question/problem

Posted 23 February 2012 - 09:30 PM

Quote

I cant seem to find a mismatched {

I think you need to review this link: Structure of a Program.

You have several missing or misplaced braces. Let's look at your code, stripped of all your commented code, and with the braces aligned for easier reading:
#include <iostream>


using namespace std;

int main ()
{

	int count = 0;                                   //start at 0
	for (count = 0 ; count < 50; count++)            //Goes up to 50, adds by 1 

	cout << "The count is " << count << endl;

}

{	
	int x = 50;
	
	while ( x > 0)
	{
		cout << "seconds to go" << x <<endl;
		x--;
	}

	return 0 ;
}


As you should be able to see you have a section of code that does not belong to any function.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1