Division

I am new to computer programming and C++. I am just finishing my first computer programming class.


This is my code in progress just started working on it and i can not get the first if statement to divide right it comes out with some decimal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  

#include <iostream>
using namespace std;

int main ()
{ 
	int choice;
	float totalhours, totalpay, totalrate;  
	
	
	cout << "Do you want to calculate you're" << endl
		   << "1. Rate." << endl << "2. Total Hours" << endl << "3. Total Pay" << endl;
	cout << "Please enter the number." << endl;
	cin >> choice;


	if (choice == 1)
	{	
		cout << "Please enter you're total pay." << endl;
		cin >> totalhours;
		cout << "Please enter you're total hours worked." << endl;
		cin >> totalpay;
		
		totalrate = totalpay / totalhours;
		
		cout << "You're rate is " << totalrate;
	}








  return 0;
}

closed account (j3Rz8vqX)
Swap lines 21 and 23.

The first prompt within the if conditional branch is asking for your total pay, not total hours.

Same applies to the second prompt within the if condition; it is asking for total hours, not total pay.

Have fun.
Wow i missed that haha. thank you for you help
Topic archived. No new replies allowed.