Total members 11893 |It is currently Fri Nov 15, 2024 10:03 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Trying to figure out how to write this program. Its a ..for loop and I never have written one. The loop is suppose to produce some kind of output.

x = 0
cout = 1;
while (cout <=25)
{
x = x-count;
count ++;
}




Author:
Newbie
User avatar Posts: 3
Have thanks: 0 time

#include<iostream>
using namespace std;

int main() {
int x = 0;
int c = 1;
while (c <=25)
{
x = x - c;
c++;
cout << x << endl;;
}
cin >> x; return 0;
}

I duno if tht is what u meant. Dun use key word like "cout" for variable names...i've modified the program...cek if that's what u want



Author:
Newbie
User avatar Posts: 16
Have thanks: 0 time

to write a for loop
first identify a variable
like int i;
then for(i=0;i<25;i++)//i starting from 0 to <25 means to 24//i++means it is ascending
{
cout<<i<<endl;
}
that code will cout from 0 up to 24
if u want the code descending
for(i=25;i>0;i--)
{
cout<<i<<endl;
}



Author:
Newbie
User avatar Posts: 2
Have thanks: 1 time

For this message the author alaa111151 has received gratitude : DrRakha

mestz6 wrote:
Trying to figure out how to write this program. Its a ..for loop and I never have written one. The loop is suppose to produce some kind of output.

x = 0
cout = 1;
while (cout <=25)
{
x = x-count;
count ++;
}


See brother u have declared x as 0 therefore looping condition is x=x-count i.e 0=0-(count).
but for seeing this result u must write a printf statement i.e printf("X= %d",x); OK !
If any problem u have contact me at ([email protected]) I would love to help my brothers.



Author:
Post new topic Reply to topic  [ 4 posts ] 

  Related Posts  to : C ++ problems
 Problems since upgrade to 3.0.6     -  
 Problems - mile200     -  
 problems with sky_miles red in IE     -  
 Skin customize problems..     -  
 problems to connect to active directory     -  
 How Can I Avoid Domain Renewal Problems?     -  
 HELP! Javascript Problems (manual Slideshows), Having troubl     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com