I know we shouldn't just , but this is painful :p
Megz, the things you need to work on are:
1) The order in which things happen - in your code, you were calculating the answer, and THEN you were getting the values from the user. Can you see why that won't work? If I want you to divide two numbers and tell me the answer, you need to know what those two numbers are BEFORE you can calculate the answer. I hope that's clear.
2) Understanding that the computer does not behave just like a human. In C++, when you divide one integer (you know what an integer is, yes?) by another, you will get back another integer. This mean, for example, that 5 divided by 2 equals 2, it does NOT equal 2.5; if you're going to programme, you have to know what numbers actually are inside the machine and how the basic mathematical operations apply to them.
I know these things sound really basic, but to code effectively you've got to realise that the machine doesn't "think" like a human. You'll see that I changed the types from int to float. It would be a good idea for you to look up int and float and understand the difference between them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
int main()
{
float thisisanumber;
float whole_number;
float total;
cout << "Please enter a number: \n";
cin >> thisisanumber;
cout << "Please enter another number:\n";
cin >> whole_number;
total = thisisanumber / whole_number; // thisisanumber divided by
cout << "The total is:\n" << total;
}
|