Hey guys,
I am a CS major at Bradley University and school is about to start so just to brush up on my C++ syntax I decided to make a simple program that would be used to study.

It is basically just a notecard program, where you enter the front of the card, then the back. you have to tell it if you have another card to enter after a card is finished, which is where I am having a problem.

After the first card, when prompted to find out if there is another card, it ignores whatever you say and just enters the catch segment of the try...catch statement. It only happens the first time through and I have tried everything I could think of.

Thanks in advance, here's the code:

oh yeah, there are a few portions of the code that I have put in just to try to help debug the program.

//Ok so let's try this notecard program one more time....

#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){

    //Variables to come:
    string front="";                    //temporarily stores the front of the notecard
    string back="";                     //temporarily stores the back of the notecard
    string response="";                 //stores whether or not the user wants to create another card
    string test1="y";                   //string to compare the user input
    string test2="n";                   //string to compare the user input
    vector<string> fronts;              //stores all of the fronts of the notecards
    vector<string> backs;               //stores all of the backs of the notecards
    bool repeat = 0;                    //used in a loop
    bool anotherCard = 1;               //used in a loop
    cout<<"Welcome to NoteCards 0.1\n";
    while (anotherCard == 1){
        //Retrieve card
        cout<<"Enter front of the card  ";
        getline (cin, front);
        cout<<"Enter the back of the card  ";
        getline (cin, back);
        //Ask for repetition
        cout<<"Do you have another card you want to add? 'y' for yes 'n' for no  ";
            getline (cin,response);
            if (test1.compare(response)==0 || test2.compare(response)==0){
                throw 1;
        } catch (int e){
            while (repeat != 1){
                cout<<"please reply 'y' or 'n'  ";
                getline (cin, response);
                if (test1.compare(response)==0 || test2.compare(response)==0){
                    repeat = 1;
        if (response.compare(test1)==0){
    for(int i = 0; i < fronts.size(); i++){
    for(int i = 0; i < backs.size(); i++){
    //If no repetition, ask for review of cards
    //Find a way to save information so input isn't needed every time
    //Ask to review again or exit
    return 0;
6 Years
Discussion Span
Last Post by Fbody

I suggest you read up on the string::compare function. It appears that you are interpreting the return value incorrectly. As a result, a valid input is considered invalid and an invalid input is considered valid.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.