Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,335 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,884 people online right now. Registration is fast and FREE... Join Now!




Where to put toupper function

 
Reply to this topicStart new topic

Where to put toupper function

rttlsnake
post 16 Feb, 2008 - 09:32 PM
Post #1


New D.I.C Head

*
Joined: 8 Feb, 2008
Posts: 10

This is a homework assignment. I have the code done so it will run correctly. I am struggling with using the toupper function though. I want to use it instead of using case 'a", case 'A' etc...

I am not sure where I place it or the exact way to code it. any pointers would be great.
CODE

#include<iostream>
#include<cctype>

using namespace std;

void LargestNum();
void SmallestNum();

int main()
{
    char option;

    do
    {
        cout << "     A - Find the largest # with a known quantity of numbers.\n";
        cout << "     B - Find the smallest # with an unknown quantity of numbers.\n";
        cout << "     C - Quit!\n";
        cout << endl;
        cout << "Please enter your choice: ";
        cin >> option;
        cout << endl;
        
        switch (option)
        {
            case 'A': LargestNum(); break;

            case 'B': SmallestNum(); break;
        }
    } while (option != 'C');

    system("PAUSE");

    return 0;
}

void LargestNum()
{
    int entry;
    int i = 0;
    int input;
    int largest = 0;

    cout << "How many numbers would you like to enter? ";
    cin >> entry;

    for (i = 0; i < entry; i++)
    {
        cout << "Number " << i+1 << ":";
        cin >> input;
        if (input > largest)
            largest = input;
    }
    
    cout << endl;
    cout << "     The largest number you entered is: " << largest << "\n";
    cout << endl;
}

void SmallestNum()
{
    int smallest, input1 = 0, i1 = 1;

    cout << endl;
    cout << "Enter as many numbers as you want, when finished type -99\n";
    cout << endl;
    
    do
    {
        cout << "Number" << i1 << ": ";
        cin >> input1;    
        i1++;
        if ((input1 < smallest) && (input1 != -99))
            smallest = input1;
    } while (input1 != -99);
    
    cout << endl;
    cout << "     The smallest number you entered is: " << smallest << "\n";
    cout << endl;
}


This post has been edited by rttlsnake: 16 Feb, 2008 - 09:35 PM
User is offlineProfile CardPM

Go to the top of the page


no2pencil
post 16 Feb, 2008 - 09:40 PM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,268



Thanked 54 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


Preferably before you test the condition...

CODE

option=toupper(option);
switch (option) {
User is online!Profile CardPM

Go to the top of the page

rttlsnake
post 16 Feb, 2008 - 09:58 PM
Post #3


New D.I.C Head

*
Joined: 8 Feb, 2008
Posts: 10

Thank you. makes sense now.



QUOTE(no2pencil @ 16 Feb, 2008 - 10:40 PM) *

Preferably before you test the condition...

CODE

option=toupper(option);
switch (option) {


User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/19/08 03:17PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month