while loops with increments

I would like to be shown a bit about how to do while loops with increments

Hi there I have recently started using Dev c++ in my computer labs at school,
I know your not here to give the ansers to my work but i would
just like somebody to point me in the write direction
It took me a while to pick up the basics but I have more of a jist now.
But the while loops still baffle me!

In one of the sheets I have been given, part I;m stuck on asks:

write a while loop that will call a function that takes two numbers, one double and one int, and raises the first number to the power of second one and return the result. I have managed to do this part without the return the result? then
the next part is the part I really dont know what to do: the while loop needs to keep incrementing the int used in the function each time, this is meant to carry on untill the result of the function call exceeds 500?
the calculation part is also meant to be in a loop?
then an output line line needs to be included for each function call, to see the effect

please help, I am utterly stuck and have searched everywhere.
I was really starting to enjoy c ++ before i could majorly stuck for hours on end!


heres what i have managed to do so far




#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>

int read_int(char [],char []);
int int1;
double double1;
/*int result; I dont know how to use this, but just know it musthere.*/

int main(){

/* int1=1
/this is me trying to get a while loop running
while (int1<500)*/

double1=read_int("number1:","lf"); int1=read_int("number2:","%d");

printf("number1 to the power of number2 = %lf \r\n", pow(double1,int1));

/*return result;*/


system ("PAUSE");
return 0;

}


int read_int(char prompt[],char format[])
// subroutine to get undisclosed varying size of number//
{
char line[100];
int retvalue;

printf("%s",prompt);
fgets(line,sizeof(line),stdin);
line[strlen(line)-1]='\0';

sscanf(line, "%d", &retvalue);

return retvalue;

}
closed account (S6k9GNh0)
1) Wrong forum. Please read the title of the forum... Is it THAT difficult for someone to figure out where to post?
2) Use [CODE] tags. If you don't know how, please look in the articles database for a tutorial although I hope you can figure it out on your own.
3) This is C++. Why do you insist on coding in C if your using C++?
4 and last) An incrementing loop should more often than not be a for loop for convenience and apropriateness. It's possible with a while loop but its pointless in my honest opinion.

1
2
3
4
5
6
int i = 0;

while (i <= 500)
{
   ++i;
}
Last edited on
Topic archived. No new replies allowed.