C++ looping command

Soldato
Joined
10 Apr 2004
Posts
13,497
Code:
#include <stdio.h>

int main() {
	
	/* declare a as a float variable */
	float a, b;
	
	/* print a prompt for the user */
	printf("Please enter a number: ");
	
	/* read the value entered into variable a */
	scanf("%f",&a);
	
	/* print a second prompt for the user */
	printf("Please enter a second number:");
	
	/* read the second value entered into variable b */
	scanf("%f",&b);
	
	/* print the value of a */
	printf("You entered %f first:\n ",a);
	
	/* print the value of b */
	printf("You entered %f second:\n",b);
	
	/* print the sum of a & b */
	printf("The sum of the two values entered: %f\n",a+b);
	
	/* print the difference of a & b */
	printf("The difference of the two values entered: %f\n",b-a);
	
	/* print the product of a & b */
	printf("The product of the two values entered: %f\n",a*b);
	
	/* print the quotient of a & b */
	printf("The quotient of the two values entered: %f\n",a/b);
	
	return(0);
	
}

Simple stuff for my Aero Eng course, but I'd like to be ahead of the game so how the hell do I loop (so I don't have to restart the app/terminal) everytime I complete a workflow?

Cheers :)
 
You could put everything in the main function before the return statement inside

Code:
while (true)
{

}

To loop indefinitely (true always evaluates to true, funnily enough!)

Although compiling as C++, that program is actually using C features. The line is often a bit murky when being taught :)
 
Last edited:
Yea we are learning C, but im going to take it abit further and go to C++.

Using XCode on OS X for it.

But that works!!

Thanks dude, I'll be back with other questions ;)
 
Back
Top Bottom