someone please help me to solve this coding...
Given 3 inputs - First input is previous reading, second input is current reading and last input is per unit charge , Write code to calculate the current bill.
Reading Format - XXXXXAAAAA where XXXXX is consumer number and AAAAA is meter reading.

Example:
input1 =ABC2012345
input2 = ABC2012660
input3 = 4
Bill = (12660 - 12345 ) * 4
output = 1260

Input and Output Format:
First input is a string that corresponds to the previous reading. Next input is a string that corresponds to the current reading. Third input is an integer that corresponds to charge per unit.

Output is an integer.

Sample Input 1:
ABCDE11111
ABCDE11222
3

Sample Output 1:
333

Recommended Answers

All 3 Replies

We don't do your homework for you. Read the terms of service for these forums. Make an effort and post your code here along with any errors or problems you are having.

If you'd like a 'nudge' about how to get started ... then please just ask.

Can you code to print a prompt and then take in a string?

If the first 5 char's of the string, (the first 2 strings),
are always the customer ID,
can you then code to extract that first 5 char sub-string?
(google C++ substr)

Can you then get the remaining char's and convert to an int?

After doing above twice ... (maybe using a loop?) ...
can you then code to print a prompt and take in an int ?
(maybe use: cin >> intValue;)

OK ... let's see your best attempt to code the above steps ...

Hint:
code/compile/test in steps ...

Firstly code a working shell C++ program that compiles ok and
prints out your prompt ok.

Then add in steps, testing each step as you go,
and see how far you can get.

Then ask for help if needed from there,
but show us the code that compiled and worked ok,
and the code for the last step where you had a problem.

Edit:
If you are to read each data set from a long file,
then could firstly open file ... as fin ... and then ...

if( fin )
{
   while( fin >> str1 >> str2 >> intValue )
   {
       // proccess data and show desired output
   }
   fin.close(); // close file
}
else // print error message re problem opening file

Opps in avove ... (forgot this was C forum)

C code could be like this:

if( fin )
{
    char str1[132], str2[132];
    int intVal = 0;
    while( fscanf( fin, "%s %s %d ", str1, str2, &intVal ) == 3 )
    {
        /* proccess data and show desired output*/
    }
    fclose( fin ); 
}
else /* print error message re problem opening file *

If the customer ID is a varaible number of char's (BUT NOT ANY DIGITS) ...
you could find the index of the first digit in that C string
and then take the sub-string (till there) ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.