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
IMAyNeed

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
Thread Forum
Simple & Reliable backup software to USB drive? Needed
Is there software that will simply backup, monitor a few folders for any changes and produce incremental backups while immediately backing up any changes or additions to a USB drive...preferably free software or inexpensive? Thanks!
Backup and Restore
Just a simple question about my RAM
Hello, I was wondering if this stats are good. I have 4GB ram DDR2 installed and before i had a issue with 3.19 avaiable ( thats fixed ). Now i was wondering if those stats are good: http://i51.photobucket.com/albums/f356/addpowerpeeps/Destop01_zpsa35fefc9.png Friendly Kinds,
Performance & Maintenance
Sony Vegas 11 - Simple Help Needed.
Hi there. Does anyone know how i can get the 'Text' option back that's usually next to 'Media Generators' and 'Video FX'. It randomly disappeared. Please see the picture to see what i mean. http://img802.imageshack.us/img802/3531/capturenq.png Thankyou.
Software
I know this is simple but......
Hi All: I am trying to use robocopy to simply backup My Documents from my PC to an external hard drive (Drive F). I would like to do the backup every other day so ideally, robocopy would copy changed files only. I created a batch file as follows: C:\Windows\system32\robocopy...
Backup and Restore
Need Desperate yet Simple Help!
I have an Acer Aspire 1641WLMi, and have just installed Windows 7 Ultimate, however I cannot change the colour of the toolbar, and I cannot get a preview of the windows that are open, it just previews it in text. Why can't I see this and how can I fix this? Need help quickly. Thank you. Scott.
General Discussion
Must be a simple fix right??.....
Can someone tell me how to turn that green "free space" into unallocated space? Here's a picture of it!! What to DO?! on Flickr - Photo Sharing! If that doesn't work I uploaded a picture to this thread! What i'm trying to do is re-combine all of my separate sections of my hard drive back...
Performance & Maintenance


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 00:17.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App