0
#include <iostream>
using namespace std;
#include "Interface.h"
#include <conio.h>




int main()
{
    apple t;

    bool quit = false;


    while(! quit)
    {
        cout<<"the original value at beginning of clock is\n"<<clock()<<"\n";
        t.start();
        cout<<"hit enter when you want to stop timer\n";
        if(cin.get()=='\n')
        {
            t.end();
            int time =t.elapsed();
            cout<<"the time difference is\n"<<time<<"\n";
            cout<<"enter yes if you want to find out time differences for more times\n";
            if(cin.get()=='y')
            {
                cout<<"from yes";
            }
            else
            {
                cout<<"from no";
                quit=false;
                break;
            }
        }
    }
    return 0;
}
2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by lotrsimp12345
0

so after you hit yes, it should print out original time and then wait for user to hit enter,then enter loop

0

It already prompts for enter again. I'm going to guess that the problem is with extra stuff being stuck in the stream when you prompt again. You should clear it out. A good way to do that is to use strings and getline so that there isn't ever any extra stuff. Here's your code with that change, but I removed the timer parts because I don't have your header:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    bool quit = false;
    string line;

    while(! quit)
    {
        cout<<"hit enter when you want to stop timer\n";
        if(getline(cin, line) && line.empty())
        {
            cout<<"enter yes if you want to find out time differences for more times\n";
            if(getline(cin, line) && line == "yes")
            {
                cout<<"from yes\n";
            }
            else
            {
                cout<<"from no\n";
                quit=false;
                break;
            }
        }
    }
    return 0;
}
0

my problem is when it prompts again. it never goes and asks the user to hit enter. because once they hit enter it stops.

This question has already been answered. 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.