Sorry guys, I've just entered this field of programming..No good knowledge i got on it...
My question is how do i end my program?
Once the addition is done And after pressing 'y' The addition program repeats and then I'm not able to get any y/n to shut down the program... sorry for my bad English ...Please tell me what error i've done and what should i do to fix it..
My code goes here below
#include<iostream.h>
#include<conio.h>
void addition()
{
clrscr();
int a,b;
cout<<"Input two numbers to add them: \n";
cin>>a>>b;
cout<<a+b;
getch();
}
void endprog()
{
char ans;
cout<<"\nEnter y to continue adding\n";
cin>>ans;
while(ans == 'y'|| ans == 'Y')
{
addition();
}
}
void main()
{
addition();
endprog();
}
Using turbo c++ ... Please reply on this ASAP.. waiting for good replies and fixes..
Why do you have getch(); inside void addition? Remove it.
If the user enters y or Y, they will be stuck in an infinite loop that calls void addition over and over.
Look at this and see the differences from your code:
1 2 3 4 5 6 7 8 9 10
char ans;
cout<<"\nEnter y to continue adding\n";
cin >> ans;
while(ans == 'y'|| ans == 'Y')
{
addition();
cout<<"\nEnter y to continue adding\n"; //ask again after every additional addition
cin >> ans; //this way the user can quit by entering something other than y or Y
}
And please use something other than Turbo C... Please! Turbo C is very old and outdated. You will be learning non-standard C++! I recommend using CodeBlocks with a gcc compiler instead.
I was using gcc compiler and codeblocks stuff in my vacations... but now due to my college and classes uses Turbo C .. we need to use the software.. This is INDIAN Education System bro .. Its hell haha.. Thanks bro and bye