Switch to full style
C++ code examples
Post a reply

C ++ problems

Thu Apr 09, 2009 3:06 am

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 ++;
}



Re: C ++ problems

Thu Apr 09, 2009 6:20 pm

#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

Re: C ++ problems

Wed Oct 27, 2010 11:32 pm

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;
}

Re: C ++ problems

Tue Jan 17, 2012 7:54 am

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.

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