Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7642725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:15:46+00:00 2026-05-31T09:15:46+00:00

I am prompting the user to enter data regarding cars. The Do…while() loop I

  • 0

I am prompting the user to enter data regarding cars. The Do…while() loop I am using works fine the first time, then does not work properly after the first time. The code is bellow, and I am using Dev-C++. Thank you for your help and time.

#include <iostream>
#include<conio.h>
#include<cstring>
#include<fstream>
#include <iomanip.h>


using namespace std;

int main()
{

  char manufacturer[16], model[16], year[10], miles[10], car_cost[12];
  char response;
  ofstream OS ("usedcars.txt", ios::out);
  cout<<"for each car please enter :"<<endl;

  do
  {
    ofstream OS ("usedcars.txt", ios::app);
    cout<<"The manufacturer: ";
    cin.getline(manufacturer, 16);
    cout<<"The model: ";
    cin.getline(model, 16);
    cout<<"The year: ";
    cin.getline(year, 8);
    cout<<"The miles: ";
    cin.getline(miles, 8);
    cout<<"The cost of car $: ";
    cin.getline(car_cost, 10);

   OS << manufacturer << setw(9) << model << setw(8) << year << setw(11)<< miles << setw(8) << car_cost << endl;
  cout<<"Do you want to continue?";
  cin>>response;

 }
 while (response!='n');  


  return 0;  
}

*******the outpu of the program********

for each car please enter :
The manufacturer: Toyota
The model: corolla
The year: 2005
The miles: 123,000
The cost of car $: 7,999
Do you want to continue?y
The manufacturer: The model: Honda
The year: Civic
The miles: 67,850
The cost of car $: 9,200
Do you want to continue?n

***usedcars.txt**************

Toyota  corolla    2005    123,000   7,999
    Honda   Civic     67,850   9,200
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:15:47+00:00Added an answer on May 31, 2026 at 9:15 am

    I suppose you press enter after entering the ‘y’ for response. But you only read in one character which is y. So the ‘\n’ gets passed to the next read which is your Manufacturer. Thus there is no data there.

    As stefaanv writes use cin.ignore. An interesting bit on this can be found here: Clearing cin input: is cin.ignore not a good way?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since Firefox is prompting the user to store data when using the HTML5 application
I'm prompting the user to input an integer and if they don't enter a
Created a AlertDialog that is used to prompting the user to enter a keyword.
i have a form where it has the default value prompting user to enter
I'm prompting the user for a filename, if they enter a valid filename the
I have an equation with 4 variables, I am prompting the user to enter
I have two text fields in my view. After prompting the user to enter
This program will calculate the average grade for 4 exams using a for loop
In the mainViewDidLoad of my NSPreferencePane, I am prompting the user to accept the
In Windows XP, MessageBox.Show() was a viable way of prompting the user when our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.