When i run this program,and choose "Y" to repeat the program,it skip the name and quantity line that prompt the user to enter data.
i try to change it to if else statement but it can't stop the repeating program.
i suppose to use the while looping but the problem was same,the program can't stop the looping.and it can't identified when i choose 'y' to end the program and keep repeating the program.
#include <iostream>
#include<string>
#include<istream>
using namespace std;
std::cin.getline() can run into problems when used with std::cin >> var.
when you you type choice and enter '\n' is still sitting in input buffer and it is read automatically by getline(cin,a); in next loop. use std::cin.getline() to ignore that new line character. Also use == in while condition.
cout << "Would you like to quit?(Y/N)" << endl;
cin >> choice;
std::cin.ignore();
while (choice == 'N')
oke. But why i can call the main like that?
is there any other way so i just use the while looping only. that one was do while looping.
thats why i call the main like that so i don't have to write the program again to repeat it.
when i choose "N", the looping skip as i mention above(sorry i change a little bit because i edit the program) and it didn't stop.
you are not going back to the start of main. You are creating a WHOLE NEW main on top of the first one, taking up the same amount of memory again, and then when you do it again you make a WHOLE NEW one on top of those two, and so on and so on and so on, each time taking up more and more and more memory until eventually you run out of memory and the whole thing crashes.
Do you know what Recursion is? main() is a special function of C/C++. It is usually the Entry point of your code, in other word where you start. If you recursively call main the program will be in an endless loop because main doesn't return anything until it exits the program. The return value on Main goes back to the Program's caller, which usually is the Operating system.
thank you. the std::cin.ignore(); works. =)
i already done if it just run one times and have no problem.
it just i must modified it as long as the user prompt to choose "N" so the program must repeat again.