arrow_back How do I set the decimal in my code?

1 vote
How to make my code work with decimals, as soon as I set the a variable to a fractional number. The program immediately calculates wrong and terminates. Silly questions. But I have a course in the basics of algorithmization and programming, just started to learn. At the distance learning can not understand.
#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
#include <iostream>

using namespace std;
int main()
int a,b,S,P;
Программа для вычисленияn\n\периметра и площади прямоугольника.\n\
Выполнил: ФИО\n\-------------------------------------\n\ИСХОДНЫЕ ДАННЫЕ:\n");
printf("Длина (м) a=");
scanf("%i", &a);
printf("Ширина (м) b=");
scanf("%i", &b);
printf("ОТВЕТ:\nПериметр P=%i (м)\nПлощадь S=%i (м.кв)",(a+b)*2,a*b);


1 comment

The code is terrible about everything. At the same time, it can be counted

1 Answer

0 votes
You are using the int type. For fractions, you need a float or double real number.

It should not be printed and read with "%i", but with "%f" or "%lf".


guzya007 , the code in the studio, please.
Fractional numbers appear, but the program does not allow you to enter the value of the variable b
And it ends right away.