Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can we stop a programme at any point in C++?
#1
Subject: How can we stop a programme at any point?
Assalam o Alaikum, Sir how can we stop a c++ programme at any point? for example if area of inner circle is putted greater or equal to area of outer circle in a programme for finding area of ring. How can i switch out without further process?
Reply
#2
Dear Student,
As you have already learned the use of conditional statements in previous lectures. We can use those conditional statements to perform the required functionality to check for the correct or incorrect input. For example, we can use if else statement to check if radius of outer circle is greater than inner circle or not and proceed accordingly. Below is the modifed program code which contains the required logic.

#include <iostream.h>

using namespace std;

double circleArea ( double);

int main ( )
{
double rad1 ;
double rad2 ;
double ringArea ;

cout << "Please enter the outer radius value:\t" ;
cin >> rad1 ;

cout << "Please enter the radius of the inner circle:\t" ;
cin >> rad2 ;

if(rad1 < rad2)
{
cout<<"\nOuter radius should not greater than inner radius";
cout<<endl<<endl;

}

else
{

ringArea = circleArea(rad1) - circleArea(rad2);

cout<< " Area of the ring having inner raduis " << rad2 << " and the outer radius " <<rad1 << " is " << ringArea ;
cout<<endl<<endl;
}

system("pause");

}

double circleArea ( double radius )
{

return ( 3.1415926 * radius * radius ) ;

}

You can also use other condition statements for implementing the above logic. Try using switch statement to see if you can do it or not.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  why we use pointers or reference except using real name of var. what is buffer point saneha 1 9,881 05-02-2011, 06:24 PM
Last Post: Vuhelper
  why we use pointers or reference except using real name of var. what is buffer point saneha 1 5,227 05-02-2011, 06:05 PM
Last Post: Vuhelper
  This programme prompts when area of inner circle is greater or equal to area of outer sana.pari 0 1,668 04-24-2011, 06:48 PM
Last Post: sana.pari
  i used if statment to stop the program and prompt the error when area of inner circle sana.pari 0 2,133 04-24-2011, 06:42 PM
Last Post: sana.pari
  Programme Not Run in C++ giving erros 2011 sana.pari 1 1,990 04-24-2011, 06:35 PM
Last Post: Support
  i got the conecpt of string array as i asked before but i did not get this point sana.pari 1 2,236 04-24-2011, 04:52 PM
Last Post: Support

Forum Jump:


Users browsing this thread: 1 Guest(s)