help me please

-
Last edited on
Hi everyone

Q1 -
how can i reads an integer number then print the least significant digit and the next least significant digit.

e.g
enter entger: 142263
the least significant digit is :3
the next least significant digit is: 6

Q2-
how can i calculate the Fahrenheit according to the following equation
Fahrenheit = Celsius + 32

1.
It might be easier to read the integer as a string. Then you can access the digits as character elements in the string.
If you read it as an integer you will have to do the math. Hint: You will probably want to use the division / and modulo % operators.

2.
If you know the degrees Celsius you just have to add 32 to get the Fahrenheit. That's what the formula says.
Last edited on
-
Last edited on
You can access the characters in a string by index the same way you access elements in an array.
-
Last edited on
I think you should try. You'll learn more that way.

At the moment your questions are very broad and it's almost as if you ask us to do the homework for you, which we will not do. If you can't get it to work after you have tried, at least you will have some code to show us and we can help with the more specific problems that you are facing.
-
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int least_significant_digit( int n )
{
    if( n < 0 ) n = -n ; // ignore sign

    // remainder of division by 10 is the
    // least significant decimal digit eg. 142263 % 10 == 3
    return n % 10 ;
}

int main()
{
    std::cout<<"Enter an intger number: " ;
    int number ;
    std::cin >> number ;

    std::cout << "number: " << number << '\n'
              << "least significant digit: " << least_significant_digit(number) << '\n'
              << "next least significant digit: " << least_significant_digit(number/10) << '\n' ;
              // dividing by 10 throws away the least significant digit. eg. 142263 / 10 == 14226
}
Thank you
Last edited on
Why should the code be deleted? If you have learnt something from it, others may too.

I know that this is homework; but the only people who would be upset by the code are 'career' teachers (usually pretty poor ones) who believe that:
There is absolutely nothing that can be learned from code written by someone else.
No student is interested in learning; every one of them would do a blind copy and paste job without any attempt at understanding. (The poorer the teacher, the higher the percentage of students for whom this this assumption tends to be be true.)
The overriding purpose of education is evaluation of knowledge, rather than the acquisition of knowledge.

IMGO, they should just be ignored (with the contempt that they deserve).
I did not mean that
This is not homework it's just Review
There is nothing left to read in this thread, which is now completely useless for the community.
Topic archived. No new replies allowed.