Need help with simple Division program

So I was trying to make a program to divide any 2 numbers, but whenever I run I get either 0 or an extremely inaccurate answer. Any help would be greatly appreciated.

Program:

#include <iostream>

using namespace std;

/*
*
*/
int main() {
int number_a, number_b, number_c;
number_c = static_cast<float>(number_c) == static_cast<float>(number_a) / number_b;
cout << "Enter first number, a. \n";
cin >> number_a;
cout << "Enter second number, b. \n";
cin >> number_b;
cout << "The result of a divided by b: " << number_c << ". \n";
return 0;
}

Example Run:
Enter first number, a.
6
Enter second number, b.
3
The result of a divided by b: 0.

RUN SUCCESSFUL (total time: 8s)

theres a lot easier way to do this.

exp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main()
{
        int a;
        int b;

        std::cout << "Enter first number, a: ";
        std::cin >> a;

        std::cout << "Enter second number, b: ";
        std::cin >> b;

        int c = a / b;
        std::cout << "The result of 'a' divided by 'b' is " << c << ".";

        return 0;
}


if you declare you're using the standard library you wouldn't have to put std::cout or std::cin but just cout or cin. try keeping it simple, keep it neat and clean. itll be a lot easier to see mistakes you make in the future.

but this program i wrote won't let you use decimals just integers. but if you replace int with float you can.
Last edited on
Topic archived. No new replies allowed.