Answer the question
In order to leave comments, you need to log in
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;
}
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question