+ 3

When I am trying to run this program this is not taking input but in other compiler than Code Play it is running without error.?

#include <iostream> #include<stdio.h> using namespace std; int main() { char ch; do{ cout<<"Enter a character:"; ch=getchar(); if(ch=='\n') ch=getchar(); cout <<endl; if(ch>=65&&ch<=90) ch=ch+32; else if(ch>=97&&ch<=122) ch=ch-32; putchar(ch); cout<<endl; } while (ch!='0'); return 0; }

23rd Sep 2018, 8:11 AM
Md Ibrahim (West Bengal, India)
Md Ibrahim (West Bengal, India) - avatar
5 Respuestas
+ 5
try not to use getchar() and putchar() in the code playground, use scanf("%c", &ch) and printf("%c", ch) also use <cstdio> instead of <stdio.h>
23rd Sep 2018, 8:46 AM
hinanawi
hinanawi - avatar
+ 5
Md Ibrahim might be a server error, here's an actual fixed version (made some mistakes in correction, sorry): #include <iostream> #include <cstdio> using namespace std; int main() { char ch; do { cout << "enter a character"; scanf("%c", &ch); if(ch == '\n') { scanf("%c", &ch); cout << endl; if(ch >= 65 && ch <= 90) ch += 32; else if(ch >= 97 && ch <= 122) ch -= 32; printf("%c", ch); cout << endl; } } while (ch != '0'); return 0; } however this code does not prompt for any input, don't know why
23rd Sep 2018, 9:02 AM
hinanawi
hinanawi - avatar
+ 3
BlazingMagpie that actually looks like kind of a serious issue that should be looked into, and also looks like all the more reason to feature a live console
23rd Sep 2018, 12:00 PM
hinanawi
hinanawi - avatar
+ 2
it is showing compilation error
23rd Sep 2018, 8:55 AM
Md Ibrahim (West Bengal, India)
Md Ibrahim (West Bengal, India) - avatar
0
hinanawi Code playground tries to interpret if input will be needed before sending code to the server to be compiled and ran. It doesn't recognize every method though. In Java it doesn't recognize direct reading from input steam, but conventional method in unused part of the code will prompt for input. Here's an example: https://code.sololearn.com/cToR0FfCzur8/?ref=app
23rd Sep 2018, 11:51 AM
BlazingMagpie
BlazingMagpie - avatar