So, if you already know the answer why bother asking?
wtf?
Printable View
Yes it is... it shows "Press any key to continue" message. You wanted one, right?
So print out a message asking if the user wants to run it again and read the input.Quote:
quantum read above what i said, i want something that when a user press 1 for addition n addition is done like user put 2+2 n result is given 4, it should be asked from user if he want to run it again or no, if he do Y then it should run again and if he do N then it should go to menu
haha lol ok when you come back read this:
after printing your great program intro ...
Calculator 1.0
blah blah
just call getch();
for you it will do, and don't worry the least about portability haha lol
in each function print the message:
do it again [y/n]
and put the code in a loop also. a do while loop is good here.
in string function you should do almost exact thing as in main.
just print the menu in a loop, read choice, do blah haha lol
lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol
If your instructor has "given you a program", as you say, then post it, already!
The thing is, short of writing out the whole program, there's no easy answer to such a vague request as you've made.
And we don't do whole programs hardly at all, because we like to see you learn to program, not just copy from a forum, and also, it takes a lot more time.
On this forum, you should ALWAYS post the code you have (or pseudo-code if you have no code), and then tell us what *specific* problem you're having, and how to fix THAT problem.
You'll wind up getting a few fixes, and suggestions, but a whole program - not likely.
That's all the time I've got right now. Good luck w your program.Code:#include <stdio.h>
#include <conio.h>
void menu(void);
void addition(void);
void division(void);
void factorial(void);
void multiplication(void);
void subtraction(void);
void stringOps(void);
char A[256] = {'\0'};
int main() {
printf("\n\nWelcome to My Calculator");
//etc.
fflush(stdin); //others will tell you it's crap. I'll tell you I use Turbo C/C++ still, and Borland
//recommends using fflush(stdin).
printf("\n\nPress Any Key to Continue");
while(!kbhit); //do nothing, notice the semi-colon here.
menu();
return 1;
}
/*everything loops out from your menu() and comes back to it, as well*/
void menu() {
char ch;
do {
printf("\n\n Calculator Main Menu. Please Select One Type of Problem, or Q to Quit")
printf("\n\n A........for Addition\n S......for Subtraction\n F.......for factorial\n D........for division");
printf("\n G........for string operations\n M........ for multiplication");
fflush(stdin);
scanf("%c" &ch);
ch = toupper(ch); //check the header needed for this,
switch (ch) {
case 'A': addition(); break;
case 'S': subtraction(); break;
case 'F': factorial(); break;
case 'D':division(); break;
case 'G': stringOps(); break;
case 'M': multiplication(); break;
default:
printf("\n I didn't understand that choice, please choose again");
}
}while(ch != 'Q');
}
}
Don't recommend undefined behavior to others. Recommended or not, there are other ways of doing it.
It's really time you got rid of Turbo C.
hahah i just got back and i found most of you are so funny.. now listen to the question carefully please.. "WHERE ON EARTH DID I SAID THAT I WANT THAT ........ TO APPEAR ON SCREEN THAT MY CALCULATOR WELCOME MSG?" ROFLLLLLLLLLLLL I only said that when that msg is display there will be a msg "Press any key" Then if a user press'es any key like shift a b c or whatever he hits, THE MENU should open lololol and btw when i got back from playing mohaa so my brain was fresh so i wrote this ........ in like 5 minutes
LOLLOLOLOLOL I R LULZCode:#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
void printing()
{
cout<<"A......Addition\n";
cout<<"S......Subtraction\n";
cout<<"D......Division\n";
cout<<"M......Multiplication\n";
cout<<"F......Factorial\n";
cout<<"P......Power\n";
cout<<"G......String Operation\n";
cout<<"E......Exit\n";
cout<<"\t\tEnter Your Choice";
}
void Addition()
{
char ch;
while(1)
{
int a,b;
clrscr();
cout<<"\t\t\t\tAddition\nEnter 1st number:";
cin>>a;
cout<<"\nEnter 2nd number:";
cin>>b;
cout<<"\n"<<a<<"+"<<b<<"="<<(a+b);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Subtraction()
{
char ch;
while(17)
{
int a,b;
clrscr();
cout<<"\t\t\t\tSubtraction\nEnter 1st number:";
cin>>a;
cout<<"\nEnter 2nd number:";
cin>>b;
cout<<"\n"<<a<<"-"<<b<<"="<<(a-b);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Division()
{
char ch;
while(1)
{
int a,b;
clrscr();
cout<<"\t\t\t\tDivision\nEnter 1st number:";
cin>>a;
cout<<"\nEnter 2nd non-zero number:";
cin>>b;
cout<<"\n"<<a<<"/"<<b<<"="<<(a/b);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Multiplication()
{
char ch;
while(1)
{
int a,b;
clrscr();
cout<<"\t\t\t\tMultiplication\nEnter 1st number:";
cin>>a;
cout<<"\nEnter 2nd number:";
cin>>b;
cout<<"\n"<<a<<"*"<<b<<"="<<(a*b);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Power()
{
char ch;
while(1)
{
int a,b;
clrscr();
cout<<"\t\t\t\tPower\nEnter number:";
cin>>a;
cout<<"\nEnter its power:";
cin>>b;
for(int i=1;i<b;i++)
a*=a;
cout<<"\n"<<a<<"^"<<b<<"="<<a;
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Factorial()
{
char ch;
while(1)
{
int a,c;
clrscr();
cout<<"\t\t\t\tFactorial\nEnter a number:";
cin>>a;
c=a;
for(int i=c-1;i>0;i--)
a*=i;
cout<<c<<"!="<<a;
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void printstr()
{
clrscr();
cout<<"\nR.....Reverse";
cout<<"\nC.....Concatenation";
cout<<"\nX.....Copy";
cout<<"\nL.....Length";
cout<<"\nB.....Back";
cout<<"\nEnter Your Choice";
}
// STRING PORTION START //
void reverse()
{
char ch;
while(1)
{
clrscr();
char str[100];
cout<<"\nEnter a String:";
scanf("%s",&str);
printf("\nReverse is %s",strrev(str));
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void concat()
{
char ch;
while(1)
{
clrscr();
char str[100],str1[100];
cout<<"\nEnter 1st String:";
scanf("%s",&str);
cout<<"\nEnter 2nd String:";
scanf("%s",&str1);
cout<<str<<"+"<<str1<<"=";
cout<<strncat(str,str1,strlen(str1));
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void copy()
{
char ch;
while(1)
{
clrscr();
char str[100],str1[100];
cout<<"\nEnter 1st String:";
scanf("%s",&str);
cout<<"\nEnter 2nd string";
scanf("%s",&str1);
clrscr();
cout<<"1st String="<<str;
cout<<"\n2nd String="<<str1;
cout<<"\nString 1 copied to string 2.....";
strcpy(str,str1);
cout<<"\nString 1="<<str;
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void length()
{
char ch;
while(1)
{
clrscr();
char str[100];
cout<<"\nEnter a String:";
scanf("%s",&str);
cout<<"\nLength of"<<str<<"is "<<strlen(str);
cout<<"\nDo you want to run again?(Y/N)";
ch=getch();
if(ch=='n' || ch=='N')
{
clrscr();
break;
}
}
}
void Strings()
{
cout<<"\t\t\t\tString Operations\n";
char ch='Y',str[10];
while(ch!='b' || ch!='B')
{
printstr();
ch=getch();
switch(ch)
{
case'R':
case'r':
reverse();
break;
case'C':
case'c':
concat();
break;
case'x':
case'X':
copy();
case'l':
case'L':
length();
break;
case'b':
case'B':
break;
default:
clrscr();
}
if(ch=='b' || ch=='B')
{
clrscr();
break;
}
}
}
void main()
{
char ch1='Y';
cout<<"\n\n\n\n\t\t\tWelcome\n\n\t\t\tMy Calculator\n\n\t\t\tVersion 1.0\n\n\t\tPress any key.......";
getch();
clrscr();
while(ch1!='e' || ch1!='E')
{
printing();
ch1=getch();
switch(ch1)
{
case'A':
case'a':
Addition();
break;
case'S':
case's':
Subtraction();
break;
case'D':
case'd':
Division();
break;
case'M':
case'm':
Multiplication();
break;
case'F':
case'f':
Factorial();
break;
case'P':
case'p':
Power();
break;
case'G':
case'g':
Strings();
break;
case'E':
case'e':
exit(0);
default:
clrscr();
}
}
}
Please stop 'loling', why are you using conio.h?
And this isnt' C... I'd suggest you study instead of playing 'mohaa'.
What's wrong with,Code:switch(ch1)
{
case'A':
case'a':
Code:switch(tolower(ch1))
{
case 'a':
...
}
Naughty.Code:void main()
Stop lolling all the time and listen to what people are saying.
oh btw ty Adak for your reply, it was somewhat close but your reply was the most appropriate amoung all others, thanks to all others as well (just for the formality) not that they did something great haha :)
Edited to remove anti-semitic comment. I'll leave the rudeness in so people know who they're dealing with. -- CornedBee
edit: zacs7 sorry but i cant stop loling at you guys, dont say stuff that dont make me lol and i wont lol :)
oh i forgot to mention in the above post .. "And its not c" LOOOOOOOOOL this is perfecty c, just edit cout to printf and cin to scanf .. and as for libraries, they can be included in both c or cpp so what are you talking about? UNCLE :)
> this is perfecty c, just edit cout to printf and cin to scanf
Er... you know how stupid that sounds?
And please stop calling me Uncle, unless you are actually my nephew -- which I hope not.
lol haha
hey i sent you a pm lol
but you seem so lol that you did not notice it yet lol
when will you be done with your mohaaa lol
lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol