new guy is probably WAY over his head...

Hi, just joined and have been using the tutorials on this site to help me get started.

I'm trying to make a program that asks you for drawing scale for architectural drawing and converts it to the full-size measurement.
I read somewhere that cin.ingnore() will just pause the program until the user hits enter but it's not working, am I implemeting it wrong?
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
using namespace std;
// define all my functions
int distance_count;
float pdistance;
string menu;
int scale;
//begins process to calculate real scale
int begin()
{
	cout << "Please enter drawing scale\n";
	cout << "1. 1/2\" to 1'\n"; //will add more options later
	cin >> scale;

	if (scale == 1)
	{
		distance_count = 2*1; //inverse of the fraction times the life scale.
	
		cout << "okay, press enter when ready to continue:\n";
	
		cin.ignore();
	
		cout << "please enter distance measured on the paper (in decimal inches):";
	
		cin >> pdistance;
	       
	       	cout << "is " << pdistance << " correct? (press enter)";
	
		cin.ignore();

		cout << "the to-scale distance is: " << distance_count * pdistance / 12 << "feet.";

}
}


//the "BOOT" function, it calls up the menu.
int BOOT()
{

	cout << "Welcome to Print Dragon!\n";
	cout << "Type \"start\" to start and \"stop\" to quit: ";
	cin >> menu;

if (menu == "start")
 {
	begin();
 }
else if (menu == "stop")
 {
	cout << "\nare you sure? (press enter to confirm)";
	cin.ignore();	
 }
}

//runs first thing and calls up the "BOOT" function
int main()
{
	
	BOOT();
	return 0;
}

This is mainly a rough design right now, I want to get it working before I add any type-safety stuff to prevent errors on bad input.
thanks for the help in advance! :)

also kinda a "for future reference" question: Is it very hard to add graphical interfaces to C++ programs? would I need to re-write this program in a diffrent style or format?
Last edited on
I read somewhere that cin.ingnore() will just pause the program until the user hits enter


It's cin.get()


question: Is it very hard to add graphical interfaces to C++ programs?

You can't mix console and graphic user interfaces.
Simply because if you rely on cout and cin you can't map that to text fields and buttons.

But what you can do is make libraries that can be used regardless which user interface you are dealing with.

If your question was whether it is easy to make a graphic UI with c++ then I can tell you everything is easy when you use wxWidgets.
everything is easy when you use wxWidgets.
okay thanks.

It's cin.get()
that doesn't work either... is there an include I need with it?
Last edited on
mbozzi,

that's not working for me, even with all the necessary includes. I understand I could probably use a system() call but I don't want it to be THAT insecure...
I don't want it to be THAT insecure...

The real issue with std::system in this context isn't that it's insecure, especially in the context of a single-user OS. But I digress.

The problem with your program as it stands is that that it leaves a newline in the input buffer before prompting the user to quit. When you call std::cin.get(), it immediately fetches the newline character present in the buffer and returns.

The way to avoid this is to dump out the extra newline in the stream buffer first:
std::cin.ignore();
and then to finally fetch one more character:
std::cin.get();

(Sorry, by the way. If I had noticed, I wouldn't have wasted your time with the link above.)
Last edited on
Topic archived. No new replies allowed.