+ 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; }
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>
+ 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
+ 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
+ 2
it is showing compilation error
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