0

i have follwoing code in c++ .i want to continue it till suer give input as 'Y' or 'y'

// my first program in C++
 #include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
//#inlcude <iostream>
 #include <stdlib.h>
 #include <conio.h>
 #include <ctime>
 
using namespace std;
 
 
void Evaluatexp(char ch[]);
//void Evaluatexp(string ch);
int main ()
{
    char postfixexp[100];
//    string postfixexp;
    char ch='Y';
    //cout << "Hello World!" << endl << endl;
    
    while(ch=='Y' || ch=='y')
    {
    cout << "Enter postfix expression to evaluate:" << endl << endl;
    gets(postfixexp);
//cin >> postfixexp;
cout << (postfixexp);
    Evaluatexp(postfixexp);
    cout << "Do you want to enter another postfix expression to evaluate? [Y/N]" << endl << endl;
//    getch(ch);
   cin >> ch;
  cout << ch;
    
   }
   system("PAUSE");
 return 0;
}

but its not working fine ..and do not ask for expression in the code ( cout << "Enter postfix expression to evaluate:" << endl << endl

any help??

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by erum
0

first You should use do while loop..
Second you should use "cin.ignore()" after getting character from user (Y/N)..
Try this following:

do
{
 // here is ur code
cin>>ch;
cin.ignore();
} while(ch=='Y' || ch=='y');

Edited by Awais Ali: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.