0
How to input 2 digit number in one character?
a part of my program is char m,n; scanf("%c %c", &m,&n); it's okay if I add numbers less than 10 for example (input like 4 3 or 4 3) but if I want to enter 43 and 54 (input like 43 54 or 4354) it outputs 4 & 3 taking only 4 and 3 as input how can I enter two digits in m or n?
3 Respostas
+ 2
you can't as m and n are characters (you can not store 2 integers in one)
Use string instead in C++, or char * in C (but in C you'll have to know the length max of the Word you'll read)
+ 1
Storing 2 values or more can be done by declaring an array of size 2 and storing each value in the array .
For example ;
int array [2] = { 43 , 45 } ;
This is an addition program :
#include <iostream>
using namespace std ;
int main ()
{
int array [2] = { 43 , 45 } ;
int sum = 0 ;
for ( int i = 0 ; i < 2 ; i++ )
sum += array [ i ] ;
cout << "Result : " << sum ;
return 0 ;
}
0
Thank you for your replies, I've found another method to solve those problems that don't require the use of characters. :)