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.
#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.