All pastes #80530 Raw Edit

Untitled

public text v1 · immutable
·published 2006-07-06 14:38 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>

int minsToSecs(int mins);
int hrsToSecs(int hrs);
int get_atoi(void);

int main()
{
   
    int upspd, hrs, mins, secs, choice;
        
    printf("This program determines the amount of bandwidth you have uploaded.\n");
    printf("Type the average upload speed (B/s): ");
    upspd = get_atoi();
    fflush(stdin);
    printf("\n-----------------------------------------------------------------\n");
    printf("How long you have been uploading for?\n");
    printf("Type the amount of hours: ");
    hrs = get_atoi();
    fflush(stdin);
    secs = hrsToSecs(hrs);
    printf("\nType the amount of minutes: ");
    mins = get_atoi();
    fflush(stdin);
    secs += minsToSecs(mins);
    printf("\n-----------------------------------------------------------------\n");
    printf("The information you require...\n\n");
    printf("How would you like it to be formatted?\n");
    printf("1 - Bytes(B)\n2 - Kilobytes (kB)\n3 - Megabytes (mB)\n");
    printf("......................................");
    scanf(" %i", &choice);
    fflush(stdin);
    switch (choice)
         {
                case '1': printf("You have uploaded a total of: %dB", upspd * secs);
                     break;
                case '2': printf("You have uploaded a total of: %fkB", (float) upspd * secs / 1024);
                     break;
                case '3': printf("You have uploaded a total of: %fmB", (float) upspd * secs / 1024 / 1024);
                     break;
                default: printf("You didn't type 1, 2 or 3...");
                     break;
         }
    while (choice != 1 || choice != 2 || choice != 3)
    {
          choice = getchar();
          fflush(stdin);
          printf("You didn't type 1, 2 or 3...");
    }
    getch();
    return(0);
}

int minsToSecs(int mins) 
{
    int secs;
    
    secs = mins * 60;
    return(secs);
}

int hrsToSecs(int hrs)
{
    int secs;
    
    secs = hrs * 60 * 60;
    return(secs); 
}

int get_atoi()
{
    char temp[10];
    int x;
    
    scanf(" %s", temp);
    x = atoi(temp);
    return(x);
}