E
eli m
Hi I made this code:
#include <stdlib.h>
#include <iostream>
using namespace std;
int main() {
int getIntx()
unsigned int ans;
double mfirstnum, msecondnum;
cout << "Type in your first number:";
mfirstnum = getIntx();
cout << "Multiply your first number by:";
msecondnum = getIntx();
ans = mfirstnum * msecondnum;
cout << ans << "\n"; }
//Get int x
int getIntx() {
double x = 0;
while(!(cin >> x)) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout << "Invalid Input. Try again:";
}
return x;
}
So, whenever I type in a decimal it rounds it up. Why is this happening?
#include <stdlib.h>
#include <iostream>
using namespace std;
int main() {
int getIntx()
unsigned int ans;
double mfirstnum, msecondnum;
cout << "Type in your first number:";
mfirstnum = getIntx();
cout << "Multiply your first number by:";
msecondnum = getIntx();
ans = mfirstnum * msecondnum;
cout << ans << "\n"; }
//Get int x
int getIntx() {
double x = 0;
while(!(cin >> x)) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout << "Invalid Input. Try again:";
}
return x;
}
So, whenever I type in a decimal it rounds it up. Why is this happening?