Link to home
Start Free TrialLog in
Avatar of cscotty
cscotty

asked on

How To Ask Question, Get Input, Clear Screen, Ask Question, Get Input, Clear Screen.....

Hello All.  I am a newbie to C++ programming.  As a matter of fact, I just read a few tutorials that really peaked my interest in C++.  I am so excited to start that I wanted to create this simple program:

In a console window (dos) I would like to ask the user a question and save the response as a variable.  Then I would like the screen to clear and repeat the process.  The only problem is that when the screen clears, it does not ask the other questions.  It just says "press any key to continue" and then closes the window.  Here is my code:

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
  int a, b, c, d;
 
  cout<<"What is your name?\n\n";
  cin>>a;
  system("cls");
 
  cout<<"How old are you?\n\n";
  cin>>b;
  system("cls");
 
  cout<<"Who is your employer?\n\n";
  cin>>c;
  system("cls");
 
  cout<<"What is your favorite website?\n\n";
  cin>>d;
  system("cls");
 
  system("PAUSE");      
  return 0;
}

This should be fairly easy for you pros out there. Is there something wrong with my code?  Obviously there is.  Can someone please help me?

Thanks,
Scott
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cscotty,

Once you make sure your input types match expected input, that should fix the problem

David Maisonave :-}
Avatar of cscotty
cscotty

ASKER

Oh My Word, AXTER You are a GENIUS!!!!!!!!!!!!!

I changed the type to "char" instead of "int" and it worked!!!!!!!  Brilliant!!!!  I am so overwhelmed right now, I gotta catch my breath.  I've been searching for the answer for over a month now and I knew I shouldve come here first.  Thanks a billion AXTER.  Truly a genius.  Here is my new code that WORKS:

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
  char a, b, c, d;
 
  cout<<"What is your name?\n\n";
  cin>>a;
  system("cls");
 
  cout<<"How old are you?\n\n";
  cin>>b;
  system("cls");
 
  cout<<"Who is your employer?\n\n";
  cin>>c;
  system("cls");
 
  cout<<"What is your favorite website?\n\n";
  cin>>d;
  system("cls");
 
  system("PAUSE");      
  return 0;
}

Thanks a BunCH!