Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is the error in this "calculator" program ??

+1 vote
asked Mar 22, 2019 by Nada Winnie (170 points)
#include "stdio.h"
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
    float x,y;
    char c;
    float r;
    
    cout << "please enter 2 numbers: "<< endl;
    cin >> x >> y >> endl;
    cout <<"please enter the operation:" << endl;
    cin >> c >> endl;
    
    switch(c)
    {
     case '+': r=x+y; break;
     case '-': r=x-y; break;
     case '*': r= x*y; break;
     case '/': r= x/y; break;
     case 'A': r=(x+y)/2 ; break;
     case '>': r=(x>y)? x : y;break;
     case '<': r=(x<y)? x : y;break;
        
    }
     cout << "the result is : "<<r<<endl ;
     system("pause");
    return 0;
}

2 Answers

+2 votes
answered Mar 22, 2019 by Admin (5,100 points)
selected Mar 22, 2019 by Nada Winnie
 
Best answer
You had passed "endl" to cin stream object. It shouldn't be passed. After removing endl to cin, its working fine.
Here is your working code snippet.
https://onlinegdb.com/HJKsd8Mu4
+1 vote
answered Mar 24, 2019 by Hacker
remove endl and the code will work fine
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...