I can't get my program to work, help?

Pages: 12
I'm trying to make a program that asks a user to enter a three digit number. One output will tell the user the floor number and the second the room number.

So far this is what I have (I just don't know where to go from here):

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
void main ()

{
int number, digit;
cout<<"Enter a three digit number";
cin>> number;
digit=
}
I'm trying to learn this on my own. Any help would be appreciated.
I don't fully understand. The program prompts for one input, the three digit number, then outputs 2 statements based on the number entered, like the first digit represents the floor, and the other two represent the room number?
i.e.,
"Enter a three digit number: 123
"That is room number 23 on floor 1.


Or do you mean something else?
atropos: that's exactly what i mean:


#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
void main ()

{
int number, digit;
cout<<"Enter a three digit or four digit number \n";
cin>> number;

int roomnumber (>99);
cout<<"the room number is \n"<<number<<endl;
cin>> roomnumber;

cout<<"the floor number is \n";

}


i need it to display it separately though.. What would you suggest I do?
why dont you first ask for a floor number and then ask for a room number ?
I already know how to do that. The purpose of this is to learn how to separate digits such as 123 into 1 and 23.
how would the program know which one to separate? 1 - 23 or 12 - 3???
Last edited on
That's where I get stuck. I'm just not sure how to tell the program to do that. I'm trying to figure out different combinations at the moment.
you're gonna have to pick some combination for the room number; either the first digit or first two digits or you could even do first and third digit but you have to pick some condition. you cant tell someone to separate something without telling them how it must be separated.
I would like it to be separated like this #-##. The first # being the floor number and the ## being room numbers.
Do you know how to use the division operator and modulus operator? They are all you need for this ;)
Ahh I wish I did! Could I maybe do it with a string operator?
Or maybe you could show me how a division and modulus operator would work?
1
2
3
4
5
6
7
int a = 12;
int b = a/10; //divides a by ten
cout << b << endl;

int c = 12;
int d = c%10; //takes the remainder of division of c by 10
cout << d << endl;
1
2
Sounds easy enough. Would you by any chance be able to do this with a string, and if so, would it be easier?
Forgot to thank you L B!
you could but it would not be easier, you would have to convert the string back into an integer.
Let's say I would start I string off like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
void main ()

{
	string number;
	string floor;
	string roomnumber;

	cout<<"Please enter a three or four digit number \n";
	getline(cin,number);



	
}


How would I separate it from here?
Hmm maybe using char would be a better idea then?
It will be far easier to not use strings. Period. Just use an int.
Pages: 12