3 Replies - 209 Views - Last Post: 11 February 2014 - 04:06 PM Rate Topic: -----

#1 Dianne21ftw  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 11-February 14

For loop

Posted 11 February 2014 - 03:37 PM

Hello </deam.in.code> community. I'm new(bie) and I got here because I was searching for some help.
I already googled my problem, but the thing is that my brain is the problem(i think).

I'm doing these tutorials to learn C++ and I don't understand what the author wants from me.
//The function uses a "for" loop to print the given character the number of times specified by the integer.
How can I make a for loop to do that?

So.. my code looks like this:

// Week 6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

void printMyInteger(int myInteger, char myChar)
{
	for () //at the second bracket it gaves me an error
	{
		
	}
}



int _tmain(int argc, _TCHAR* argv[])
{
	//printMyInteger(5, 65);
	return 0;
}





So.. here is my error:

Error	1	error C2143: syntax error : missing ';' before ')'	d:\workspace\university\tools for games and animation\workshops\week 6\week 6\week 6\week 6.cpp	10	1	Week 6
Error	2	error C2143: syntax error : missing ';' before ')'	d:\workspace\university\tools for games and animation\workshops\week 6\week 6\week 6\week 6.cpp	10	1	Week 6
	3	IntelliSense: expected an expression	d:\workspace\university\tools for games and animation\workshops\week 6\week 6\week 6\week 6.cpp	10	7	Week 6



I would really appreciate any kind of help. Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: For loop

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8957
  • View blog
  • Posts: 33,581
  • Joined: 12-June 08

Re: For loop

Posted 11 February 2014 - 03:45 PM

A for loop requries some crucial pieces of information to run right.

1. loop control variable initialization
2. condition to continue looping
3. updating the loop control variable.


Typically the format is:
for(1; 2; 3)
{
// stuff to loop.
}



Example:

for(int lcv = 0; lcv < 5; lcv++)
{
   count << lcv;
}


"int lcv = 0"
- I define a loop control variable (lcv) that has scope while the for loop is active.

"lcv < 5"
- I want the loop to continue while the variable lcv is less than five.

"lcv++"
- after each loop iteration increment lcv by one. This ensures we, eventually, hit the condition.
Was This Post Helpful? 1
  • +
  • -

#3 Black_Epiphany  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 64
  • Joined: 02-February 14

Re: For loop

Posted 11 February 2014 - 03:54 PM

This tutorial is good for flow control http://www.cplusplus...torial/control/

or this

http://msdn.microsof...y/b80153d8.aspx
Was This Post Helpful? 1
  • +
  • -

#4 Dianne21ftw  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 11-February 14

Re: For loop

Posted 11 February 2014 - 04:06 PM

Thank you very very very very much guys! You are awesome!
Done:
// Week 6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

void printMyInteger(int myInteger, char myChar)
{
	for (int i = 0; i < myInteger; i++)
	{
		cout << myChar << endl;
	}
}



int _tmain(int argc, _TCHAR* argv[])
{
	printMyInteger(5, 65);
	
	return 0;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1