problem on second getline loop

I have created a project that requests the user to enter and rate pizza, however my current code doesnt seem to work right after the first interation. when it asks the user if they want to rate another pizza and they say yes it skips past the first question that requests for input of the pizza name

Here is my code.  (whats wrong... help oh coding gods)



#include <iostream.h>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <fstream>

int main()
{
      char name[256], name2[256], name3[256];
      float dia[3];
      float oz[3];
      int score[3];
      char fileName[30] = "MyPizza";
      string sp = " ";
      string d = " - ";
      char re;



         cout << "\t\t*******************************\n";
         cout << "\t\t****** Pizza Analyzers ********\n";
         cout << "\t\t*******************************\n\n";


         cout << "Please enter the name of one pizza:  ";
         cin.getline (name,256);


         cout << "\n\nPlease enter the diameter of the pizza in inches :  ";
         cin >> dia[0];

         cout << "\n\nPlease enter the weight in ounces :  ";
         cin >> oz[0], a >> dummychar >> b;

         cout << "\n\nPlease enter your rating for this pizza, (0-5) :  ";
         cin >> score[0];

         cout << "Would you like to rate another pizza? (y/n) :  ";
         cin >> re;

         if (re == 'y') {
            system("cls");

            cout << "\n\nPlease enter the name of one pizza:  ";
            cin.getline (name2,256);

            cout << "\n\nPlease enter the diameter of the pizza in inches :  ";
            cin >> dia[1];

            cout << "\n\nPlease enter the weight in ounces :  ";
            cin >> oz[1];

            cout << "\n\nPlease enter your rating for this pizza, (0-5) :  ";
            cin >> score[1];

            if (score[1] >= 6) {
               cout << "Please enter a rating from 0-5 :  ";
               cin >> score[1];
            }

            cout << "Would you like to rate another pizza? (y/n) :  ";
            cin >> re;

            if (re == 'y') {
               system("cls");

               cout << "Please enter the name of one pizza excluding all titles :  ";
               cin.getline (name3,256);

               cout << "\n\nPlease enter the diameter of the pizza in inches :  ";
               cin >> dia[2];

               cout << "\n\nPlease enter the weight in ounces :  ";
               cin >> oz[2];

               cout << "\n\nPlease enter your rating for this pizza, (0-5) :  ";
               cin >> score[2];

               if (score[2] >= 6) {
                  cout << "Please enter a rating from 0-5 :  ";
                  cin >> score[2];
               }

               system("cls");

               cout << name[0] << sp << d << dia[0] << " diameters " << oz[0] << " ounces with a rating of : " << score[0] << endl << endl;
               cout << name[1] << sp << d << dia[1] << " diameters " << oz[1] << " ounces with a rating of : " << score[1] << endl << endl;
               cout << name[2] << sp << d << dia[2] << " diameters " << oz[2] << " ounces with a rating of : " << score[2] << endl << endl;

               ofstream Pizza(fileName, ios::out);
               Pizza << name[0] << sp << d << dia[0] << " diameters " << oz[0] << " ounces with a rating of : " << score[0] << endl;
               Pizza << name[1] << sp << d << dia[1] << " diameters " << oz[1] << " ounces with a rating of : " << score[1] << endl;
               Pizza << name[2] << sp << d << dia[2] << " diameters " << oz[2] << " ounces with a rating of : " << score[2] << endl;
            }
            else {
                 system("cls");

                 cout << name[0] << sp << d << dia[0] << " diameters " << oz[0] << " ounces with a rating of : " << score[0] << endl << endl;
                 cout << name[1] << sp << d << dia[1] << " diameters " << oz[1] << " ounces with a rating of : " << score[1] << endl << endl;

                 ofstream Pizza(fileName, ios::out);
                 Pizza << name[0] << sp << d << dia[0] << " diameters " << oz[0] << " ounces with a rating of : " << score[0] << endl;
                 Pizza << name[1] << sp << d << dia[1] << " diameters " << oz[1] << " ounces with a rating of : " << score[1] << endl;
            }
         }
         else {
              system("cls");

              cout << name[0] << sp << d << dia[0] << " diameters " << oz[0] << " ounces with a rating of : " << score[0] << endl;

              ofstream Pizza(fileName, ios::out);
              Pizza << name[0] << sp << d << dia[0] << " diameters " << oz[0] << " ounces with a rating of : " << score[0] << endl;
         }

      system("PAUSE");
      return 0;
}
xardiousAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xardiousAuthor Commented:
lastly how can i get this program to except fractions as well for input?
0
xardiousAuthor Commented:
please ignore / delete this part on lline 25 , a >> dummychar >> b
0
rcarlanCommented:
Change the declaration of 're' from:

char re;

to:

char re[256];


You will also have to change:

if (re == 'y')

to

if (_stricmp(re, "y") == 0)


Depending on the compiler you're using, you may have to use _strcmpi instead of _stricmp. Also, you may have to drop the leading underscore.


Finally, you may want to consider using a loop instead of three separate input blocks. Something like:

do
{
    system("cls");

    cout << "\n\nPlease enter the name of one pizza:  ";

    // ...

    cout << "Would you like to rate another pizza? (y/n) :  ";
    cin >> re;

} while (_stricmp(re, "y") == 0);


That is, assuming you've already covered do-while loops in class ;-)

Accepting fractions as input (i.e. 2/3) is not that easy. You'd have to read them as text, then look for the '/' character, and if present convert the text preceding it to a number and the text following the '/' to another number, and divide them. You'd also have to handle the situation where the user does not enter a fraction (i.e. if you do not find '/' convert the entire input text to a number).

Radu
0
novitiateCommented:
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <fstream>

#define MAX_RATINGS 3
using namespace std;




int main()
{
      char names[MAX_RATINGS][256];// name2[256], name3[256];
      float dia[MAX_RATINGS];
      float oz[MAX_RATINGS];
      int score[MAX_RATINGS];
      char fileName[30] = "MyPizza";
      string sp = " ";
      string d = " - ";
      char re;
      int count = 0;
      
      do{
            system("cls");
            
            cout << "\t\t*******************************\n";
            cout << "\t\t****** Pizza Analyzers ********\n";
            cout << "\t\t*******************************\n\n";
            
            
            cout << "Please enter the name of one pizza:  ";
            cin.getline (names[count],256);
            
            
            cout << "\n\nPlease enter the diameter of the pizza in inches :  ";
            cin >> dia[count];
            
            cout << "\n\nPlease enter the weight in ounces :  ";
            cin >> oz[count];// a >> dummychar >> b;
            
            cout << "\n\nPlease enter your rating for this pizza, (0-5) :  ";
            cin >> score[count];
            
            cout << "Would you like to rate another pizza? (y/n) :  ";
            cin >> re;
            cin.get();
      }while( (++count < MAX_RATINGS) && (re == 'y'));
      
      system("cls");
      ofstream Pizza(fileName, ios::out);
      
      for(int i = 0; i < count; ++i)
      {
            cout << names[i] << sp << d << dia[i] << " diameters " << oz[i] << " ounces with a rating of : " << score[0] << endl << endl;
            Pizza << names[i] << sp << d << dia[i] << " diameters " << oz[i] << " ounces with a rating of : " << score[0] << endl;
      }
      system("PAUSE");

      return 0;
}

_novi_
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.