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

Pages: 12
Jan 30, 2012 at 3:24am
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=
}
Jan 30, 2012 at 3:45am
I'm trying to learn this on my own. Any help would be appreciated.
Jan 30, 2012 at 4:05am
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?
Jan 30, 2012 at 4:13am
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?
Jan 30, 2012 at 4:28am
why dont you first ask for a floor number and then ask for a room number ?
Jan 30, 2012 at 4:34am
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.
Jan 30, 2012 at 4:38am
how would the program know which one to separate? 1 - 23 or 12 - 3???
Last edited on Jan 30, 2012 at 4:38am
Jan 30, 2012 at 4:47am
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.
Jan 30, 2012 at 5:02am
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.
Jan 30, 2012 at 5:03am
I would like it to be separated like this #-##. The first # being the floor number and the ## being room numbers.
Jan 30, 2012 at 5:07am
Do you know how to use the division operator and modulus operator? They are all you need for this ;)
Jan 30, 2012 at 5:21am
Ahh I wish I did! Could I maybe do it with a string operator?
Jan 30, 2012 at 5:24am
Or maybe you could show me how a division and modulus operator would work?
Jan 30, 2012 at 5:30am
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
Jan 30, 2012 at 5:32am
Sounds easy enough. Would you by any chance be able to do this with a string, and if so, would it be easier?
Jan 30, 2012 at 5:32am
Forgot to thank you L B!
Jan 30, 2012 at 5:34am
you could but it would not be easier, you would have to convert the string back into an integer.
Jan 30, 2012 at 5:36am
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?
Jan 30, 2012 at 5:38am
Hmm maybe using char would be a better idea then?
Jan 30, 2012 at 1:06pm
It will be far easier to not use strings. Period. Just use an int.
Pages: 12