Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ getline (beginner)

Name: Anonymous 2010-09-16 20:40

So i wrote this program just as a small starter to get the name of a substance and get its ph level from user. then it tells the user if the substance is either an acid, base, or neutral.

But...

i'm having trouble with the second part at getline(cin, sub2); the whole program just collapses there. at first i thought it was a logic error, but i found none..

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
    string sub1, sub2, sub3; //declares variables to be used
    double ph1, ph2, ph3;    //decalares ph levels to be used
   
        cout<< "Please enter the name of the first substance" << endl; //asks for 1st substance
        getline(cin, sub1);                                                // gets substance 1 information w/ spaces
        cout << "Enter the Ph level of " << sub1 << endl;                // enter ph of substanace 1
        cin >> ph1;                                                        // gets ph level from user
            if (ph1 < 0 ||  ph1 > 14) //declares ph to be only in levels of 0-14
            {    cout << sub1  << " is not a vaid PH level\n";
            }
            else if (ph1 <= 6 && ph1 <= 14) //Acid requirements
            { cout << sub1  << " is an Acid\n";
            }
            else if (ph1 >= 8 && ph1 <= 14) //base requirements
            {    cout << sub1  << " is a Base\n";
            }
            else if (ph1 == 7 && ph1 <= 14) //neutral requirements
            {    cout << sub1  << " is neutral\n";
            }

        cout<< "Please enter the name of the second substance" << endl;    //asks for second substance name
        getline(cin, sub2);                                                //gets second subs name w/ spaces
        cout << "Enter the Ph level of " << sub2 << endl;                //asks for ph of sub2
        cin >> ph2;                                                        //get ph of level from user
            if (ph2 < 0 ||  ph2 > 14) //declares ph to be only in levels of 0-14
            {    cout << sub2 << " is not a vaid PH level\n";
            }
            else if (ph2 <= 6 && ph2 <= 14) //Acid requirements
            { cout << sub2  << " is an Acid\n";
            }
            else if (ph2 >= 8 && ph2 <= 14) //base requirements
            {    cout << sub2  << " is a Base\n";
            }
            else if (ph2 == 7 && ph2 <= 14) //neutral requirements
            {    cout << sub2  << " is neutral\n";
            }
   
        cout<< "Please enter the name of the third substance" << endl;    //asks for third substance name
        getline(cin, sub3);                                                //gets third subs name w/ spaces
        cout << "Enter the Ph level of " << sub3 << endl;                //asks for ph of sub3
        cin >> ph3;                                                        //get ph of level from user
            if (ph2 < 0 ||  ph2 > 14) //declares ph to be only in levels of 0-14
            {    cout << sub2 << " is not a vaid PH level\n";
            }
            else if (ph2 <= 6 && ph2 <= 14) //Acid requirements
            { cout << sub2  << " is an Acid\n";
            }
            else if (ph2 >= 8 && ph2 <= 14) //base requirements
            {    cout << sub2  << " is a Base\n";
            }
            else if (ph2 == 7 && ph2 <= 14) //neutral requirements
            {    cout << sub2  << " is neutral\n";
            }
    return 0;
}

Name: Over 1000 Thread 2010-12-05 16:35 Over 1000

This thread has over 1000 replies.
You can't reply anymore.

Name: VIPPER 2010-12-21 13:59

Over 1000

JEWS

This thread has over 1000 replies.
You can't reply anymore.

A fatal error occured!
You're not allowed to reply to this thread.
If you're making a new thread, try entering a subject for it dum-dum.

This thread is threadstopped. You can't reply anymore.

Over 1000 Thread

Name: Over 1000 Thread 2010-12-21 13:59 Over 1000

This thread has over 1000 replies.
You can't reply anymore.

Name: Anonymous 2011-02-03 3:35

Name: Over 1000 Thread 2011-02-03 3:35 Over 1000

This thread has over 1000 replies.
You can't reply anymore.

Name: Anonymous 2011-11-10 11:34

>>1006
fuck you I'll reply if I want to

Name: Over 1000 Thread 2011-11-10 11:34 Over 1000

This thread has over 1000 replies.
You can't reply anymore.

Newer Posts