C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old February 9th, 2003, 09:07 PM
JoeS JoeS is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 1 JoeS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
looping, and inputing this info

IM TRYIING TO ADD THIS INFO TO MY PROGRAM BELOW. (this is just part of it).. HOW DO I DO THIS. IM NEW
i need to calcule for tuition..im not good on the , and loops, and using constants.....
its asks for name how many credits....etc. i need to make it print up on the output box as resident or non resident when they push r or n.

also it calculates how much money it cost per credit. for instance a resident student pays $200 per credit and cannot go above $3300 quater.

a non resident pays 400 a credit and cannot go above 5500

full time is 12 credits, and they cant go above 20 credits

so it needs to calculate their costs depending on how many credits they enter...





cout << "Enter the first name: ";
cin>> sFirst_name;
cin.ignore( 10000, '\n');

cout << "Enter the last name: ";
cin>> sLast_name;
cin.ignore( 10000, '\n');

cout << "Are you a resident? (Y/N) ";
cin>> Resident;
cin.ignore( 10000, '\n');

cout << "How many credits are you taking: ";
cin>> iCredits;
cin.ignore( 10000, '\n');
{
((iCredits <0) || (iCredits >20));
cout << "Error: done"<<endl;
}

{
if ((Resident == 'R') || (Resident == 'r'));


Res_Tuition = ((iCredits) * (Res_Cred));
cout << "tuition =" << Res_Tuition << endl;
}

if((Resident == 'N') || (Resident =='n'));

{
Non_Res_Tuition = ((iCredits) * (Non_Res_Cred));
cout << "tuition =" << Non_Res_Tuition << endl;
}

Reply With Quote
  #2  
Old February 10th, 2003, 05:14 PM
vpopper's Avatar
vpopper vpopper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Southern California
Posts: 73 vpopper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 24 sec
Reputation Power: 9
How about this:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

// CPC = Cost Per Credit
const int CPC_NONRES = 400;
const int CPC_RES    = 200;

// max tuition
const int MAX_NONRES = 5500;
const int MAX_RES    = 3300;

template<class T> inline T MIN(T a, T b) { return (a < b) ? a : b; }
template<class T> inline T MAX(T a, T b) { return (a > b) ? a : b; }

// -----------------------------------------------------------------

string prompt(const string& s)
{
    string ans;

    while (true) {
        cout << s;
        cin >> ans;

        if (cin.bad() || cin.fail()) {
            cout << "** Input error. Try again." << endl << endl;
            continue;
        }
        if (!ans.length())
            break;

        cin.ignore(256, '\n');
        break;
    }

    return ans;
}

// -----------------------------------------------------------------

int main()
{
    string fname, lname, is_res, ncredits;
    int credits = 0;
    int cpc = CPC_NONRES;
    int max = MAX_NONRES;

    fname  = prompt("\nEnter your first name: ");
    lname  = prompt("Enter your last name: ");
    is_res = prompt("Are you a resident? (y/n): ");

    while (true) {
        ncredits = prompt("Number of credits: ");
        credits  = atoi(ncredits.c_str());

        if (credits > 0 && credits <= 20)
            break;

        cout << "** Invalid answer. Must be 1-20." << endl << endl;
    }

    if (is_res.at(0) == 'Y' || is_res.at(0) == 'y') {
        cpc = CPC_RES;
        max = MAX_RES;
    }

    char* total;
    char* cost;
    sprintf(cost,  "$%.2f", (float)cpc);
    sprintf(total, "$%.2f", (float)MIN<int>((credits * cpc), max));

    printf("\nTuition for %s %s:\n\n", fname.c_str(), lname.c_str());
    printf("   CREDITS   |   PER CREDIT   |      TOTAL\n");
    printf("-------------+----------------+-----------\n");
    printf("   %7d   |   %10s   |   %8s\n\n", credits, cost, total);

    return EXIT_SUCCESS;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > looping, and inputing this info


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway