Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Simple C++ Help Needed

24 Aug 2012   #1

Windows 7 Ultimate 64-bit
 
 
Simple C++ Help Needed

I recently finished an MS Project, and now gotta finish this.
The thing is I don't have access to my main computer's Windows partition (I mean write access) and some other problems.
That didn't just took my time, but made me tired also.
I will be glad if someone can find the error in this code, because I am really tired of trying and cannot think clearly anymore.

Now, as long as I do not enter more than 15 characters, everything is fine. But when I enter more than 15 characters, it displays every cout and then displays the cout that starts with "Either".

How can I fix that?

All I need to achieve is
"Be sure the names do not overflow the arrays".

I know it is Friday, and I know this is not a C++ forum, but it is the best forum on the internet!
Probably, just by looking at the red section; you will find what needs to be done easily.

Thank you.

Code:
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    const int SIZE=16;
    char f1[SIZE], f2[SIZE], f3[SIZE], l1[SIZE], l2[SIZE], l3[SIZE];
    double t1, t2, t3;

    cout << "This program will put the best three runner\n"
            "in order of their finishing time."
            "\nPlease enter runners' details.\n\n"
            "***WARNING***: Last names and first names will be displayed with\n"
            "the first 15 characters only and miliseconds will be displayed with\n"
            "three decimal points only.\n\n";
    
    cout << "Runner Number 1 Details\n"
            "-----------------------\n"
            "Last Name              : ";
    cin.getline(l1, SIZE);
    cout << "\nFirst Name             : ";
    cin.getline(f1, SIZE);
    cout << "\nFinish Time(In Seconds): ";
    cin >> t1;
        
    cout << "Runner Number 1 Details\n"
            "-----------------------\n"
            "Last Name              : ";
    cin.ignore();
    cin.getline(l2, SIZE);
    cout << "\nFirst Name             : ";
    cin.getline(f2, SIZE);
    cout << "\nFinish Time(In Seconds): ";
    cin >> t2;

    cout << "Runner Number 1 Details\n"
            "-----------------------\n"
            "Last Name              : ";
    cin.ignore();
    cin.getline(l3, SIZE);
    cout << "\nFirst Name             : ";
    cin.getline(f3, SIZE);
    cout << "\nFinish Time(In Seconds): ";
    cin >> t3;
    
    
    if (t1==t2||t1==t3||t2==t3||t1<=0||t2<=0||t3<=0)
    {
        cout << "\n\nEither you have entered the same finishing time for different runners\n"
                "or one or more finishing time is smaller than or equal to 0.\n"
                "Please restart the program and enter correct finishing times.\n\n";
                
    system("pause");
    return 0;
    }
    else
    {
        cout << "\n\nHere are the runners displayed according to their finishing time:\n\n";

        if (t1<t2&&t1<t3)
        {
            if (t2<t3)
            {
                cout << "1. " << l1 << ", " << f1 << "    " << fixed << setprecision(3) << t1 << endl;
                cout << "2. " << l2 << ", " << f2 << "    " << fixed << setprecision(3) << t2 << endl;
                cout << "3. " << l3 << ", " << f3 << "    " << fixed << setprecision(3) << t3 << "\n\n";
            }
            else
            {
                cout << "1. " << l1 << ", " << f1 << "    " << fixed << setprecision(3) << t1 << endl;
                cout << "2. " << l3 << ", " << f3 << "    " << fixed << setprecision(3) << t3 << endl;
                cout << "3. " << l2 << ", " << f2 << "    " << fixed << setprecision(3) << t2 << "\n\n";
                
            }
        }
        else if (t2<t1&&t2<t3)
        {
            if (t1<t3)
            {
                cout << "1. " << l2 << ", " << f2 << "    " << fixed << setprecision(3) << t2 << endl;
                cout << "2. " << l1 << ", " << f1 << "    " << fixed << setprecision(3) << t1 << endl;
                cout << "3. " << l3 << ", " << f3 << "    " << fixed << setprecision(3) << t3 << "\n\n";
            }
            else
            {
                cout << "1. " << l2 << ", " << f2 << "    " << fixed << setprecision(3) << t2 << endl;
                cout << "2. " << l3 << ", " << f3 << "    " << fixed << setprecision(3) << t3 << endl;
                cout << "3. " << l1 << ", " << f1 << "    " << fixed << setprecision(3) << t1 << "\n\n";
            }
        }
        else
        {
            if (t2<t1)
            {
                cout << "1. " << l3 << ", " << f3 << "    " << fixed << setprecision(3) << t3 << endl;
                cout << "2. " << l2 << ", " << f2 << "    " << fixed << setprecision(3) << t2 << endl;
                cout << "3. " << l1 << ", " << f1 << "    " << fixed << setprecision(3) << t1 << "\n\n";
            }
            else
            {
                cout << "1. " << l3 << ", " << f3 << "    " << fixed << setprecision(3) << t3 << endl;
                cout << "2. " << l1 << ", " << f1 << "    " << fixed << setprecision(3) << t1 << endl;
                cout << "3. " << l2 << ", " << f2 << "    " << fixed << setprecision(3) << t2 << "\n\n";
            }
        }

        }
    system("pause");
        return 0;
}
My System SpecsSystem Spec
Reply

Thread Tools



Similar help and support threads for2: Simple C++ Help Needed
Thread Forum
Sony Vegas 11 - Simple Help Needed. Software
I know this is simple but...... Backup and Restore
A simple question...i think Network & Sharing
PLEASE HELP! (Simple Instructions..please!) BSOD Help and Support
Need Desperate yet Simple Help! General Discussion
Must be a simple fix right??..... Performance & Maintenance
Windows 7 "simple" sharing tutorial needed! Network & Sharing

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 07:21 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33