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?
#include <iostream>
#include <string>
usingnamespace 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();
}
elseif (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?
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...
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.)