program skips an input prompt

perkeyone

something clever
Reaction score
71
hey, im making a program to simulate a turing machine.
the part where i enter the tape data gets skipped over when i debug.
it outputs the prompt "Please input the initial tape configuration:"
but then it immediately outputs the next prompt "Please input the maximum number of steps: "
this is the code concerning the tape input
Code:
    i=0;
    cout<<"Please input the initial tape configuration:"<<endl;
    do{
        cin.get(temp);
        tape[i]=temp;
        i++;
    }while(temp!='\n');
and here is the full code
Code:
//Calvin Perkey
//Lab3
#include<iostream>
using namespace std;

int main(){
    int num, index=0, i=0, j, max, step=0, state=0;
    char rule[5][20], tape[50], temp;
    bool match;
    for(i=0;i<50;i++){
        tape[i]='b';}
    cout<<"Please input the number of quintuples: ";
    cin>>num;
    cout<<"Please input the "<<num<<" quintuples:"<<endl;
    i=0;
    while(i<num){
        j=0;
        while(j<5){
            cin.get(temp);
            switch(temp){
                case '\n':
                    i++;
                    break;
                case ' ':
                     //do nothing
                default:
                    rule[j][i]=temp;
                    j++;}}}
    i=0;
    cout<<"Please input the initial tape configuration:"<<endl;
    do{
        cin.get(temp);
        tape[i]=temp;
        i++;
    }while(temp!='\n');
    cout<<"Please input the maximum number of steps: ";
    cin>>max;
    cout<<"Start state 0"<<endl;
    while(step<=max){
        for(i=0;i<num;i++){
            if(rule[0][i]==state+'0'&&rule[1][i]==tape[index]){
                match=true;
                tape[index]==rule[2][i];
                state==rule[3][i];
                if(rule[4][i]=='r'||rule[4][i]=='R'){
                    index++;}
                if(rule[4][i]=='l'||rule[4][i]=='L'){
                    index--;}
                step++;
                cout<<"Tape ";
                j=0;
                for(j=0;j<50;j++){
                    if(tape[j]!='b'){
                        cout<<tape[j];}}
                cout<<" State "<<state;
                break;}}
       if(!match){
           break;}}
    return 0;}
also does anyone know of a good c++ help site?
this one is ok but honestly theres not much traffic in this part of the forum and i cant really get help as quickly as i need to.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top