E
E
ElectroEvolution2017-09-06 19:17:37
C++ / C#
ElectroEvolution, 2017-09-06 19:17:37

Why is the output incorrect on the command line?

I compile the code and it gives me some incomprehensible crap. I tried googling, but I didn't find anything useful...

#include <stdio.h>

main()
{
    //обьявление и определение некоторых переменных
    char firstInitial, middleInitial;
    int number_of_pencils;
    int number_of_notebooks;
    float pencils = 0.23 ;
    float notebooks = 2.33;
    float lunchbox = 4.99;
    //информация для первого ребенка
    firstInitial = 'J';
    middleInitial = 'R';
    number_of_pencils=7;
    number_of_notebooks=5;
    //выводимый результат для первого ребенка
    printf("%с%с need %d pencils and %d notebooks and 1 luchbox \n",firstInitial, middleInitial,number_of_pencils, number_of_notebooks);
    printf("Total cost is %.2f \n", number_of_pencils*pencils + number_of_notebooks*notebooks+lunchbox);
    //информация для второго ребенка
    firstInitial = 'M';
    middleInitial = 'J';
    number_of_pencils=10;
    number_of_notebooks=3;
    //выводимый результат для второго ребенка
    printf("%c%c needs %d pencils and %d notebooks and 1 lunchbox \n",firstInitial, middleInitial, number_of_pencils, number_of_notebooks);
    printf("The total cost is $%.2f \n", number_of_pencils*pencils+number_of_notebooks*notebooks+lunchbox);
    return 0;

}

Everything is fine with the second child. And the initials show and correctly show the number of pens and notepads, but something is wrong with the first child ... Here is a photo:
b98c114a8c754c6b900e377a9ee8aa3a.png
What is it and how to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Dubrovin, 2017-09-06
@z3apa3a

You have Russian c instead of Latin c in %c.

D
Derevyanko Alexander, 2017-09-06
@dio4

Error at line
printf("%s%s need %d pencils and %d notebooks and 1 luchbox \n",firstInitial, middleInitial,number_of_pencils, number_of_notebooks);
in that you apparently copied it from a pdf file (or you accidentally typed some service characters in the Russian layout) and there are characters there that should not be there. REPEAT it with your hands carefully in English. layout and everything will be fine :)
Everything went well for me and here is the output (I attach a screenshot):
$ ./tmp
JR need 7 pencils and 5 notebooks and 1 lunchbox
Total cost is 18.25
MJ needs 10 pencils and 3 notebooks and 1 lunchbox
The total cost is$14.28
0cbb395b69db4011ab0c8566a73eadf0.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question