Sheeee-it. I got some programming knowledge for you.
Gorillas on Qbasic is the bomb. Nibbler, not so much.
Oh how the Radioshack at the mall hated me C:\format bitches!!!
Gorillas ranks second on my coolest games ever made right behind Oregon Trail.
Sheeee-it. I got some programming knowledge for you.
Gorillas on Qbasic is the bomb. Nibbler, not so much.
Oh how the Radioshack at the mall hated me C:\format bitches!!!
Gorillas ranks second on my coolest games ever made right behind Oregon Trail.
Dude, Nibbler ROCKS!! Especially when speed 99. At least on a 25MHz 386. It was too ****ing fast on 486's.
I checked the libc man and the above won't work, you'll probably have to use an if structure with floor and ceil of some sort to get it working unless my horrible knowledge of C is making me forget a function in math.h.The requirement for the question was to have the entire output be in integers. It also said to "round to the nearest integer". This is a Chapter 6 question in my textbook that says I should only use the header <stdio.h>, a for loop, and integer values. I'm not to use any if structures, ceil, floor or extra headers. That output that you see in my first post is the best I got from it. However, working out the values on a calculator, some celsius values don't appear properly rounded off like "-6", "-3", and "37". When I put the values in float, the values are correct. It's just in int that don't appear correct to me. If this is the way C interprets the values in int, then there is nothing else I can do with my program. However, if there is another way to make the values appear properly rounded in int, I would like to know.
Sheeee-it. I got some programming knowledge for you.Oh my God. Those games bring back memories! I loved playing Gorillas in QBasic. It was WORMS before WORMS! :D
Gorillas on Qbasic is the bomb. Nibbler, not so much.
Oh how the Radioshack at the mall hated me C:\format bitches!!!
Gorillas ranks second on my coolest games ever made right behind Oregon Trail.
The requirement for the question was to have the entire output be in integers. It also said to "round to the nearest integer". This is a Chapter 6 question in my textbook that says I should only use the header <stdio.h>, a for loop, and integer values. I'm not to use any if structures, ceil, floor or extra headers. That output that you see in my first post is the best I got from it. However, working out the values on a calculator, some celsius values don't appear properly rounded off like "-6", "-3", and "37". When I put the values in float, the values are correct. It's just in int that don't appear correct to me. If this is the way C interprets the values in int, then there is nothing else I can do with my program. However, if there is another way to make the values appear properly rounded in int, I would like to know.If you're using ints to do the calculation, then you'll never be able to round the fractional part to the nearest integer because you'll only get whole numbers as a result. In other words, integer division drops the remainder (truncate). Now you could do the calculation using floats and then display the floats to make them look like ints. But that has nothing to do with the calculation, it's just printing them to the screen in a particular format.
It also said to "round to the nearest integer".
Oh my God. Those games bring back memories! I loved playing Gorillas in QBasic. It was WORMS before WORMS! :D
Anyone here know what the math formula is to calculate monthly sales projections? I need it in order to finish the last question on Chapter 6 of my programming textbook. The whole program for that question is already done. I just don't know what the monthly sales forecast formula is. ](*,)
This thread is screaming nodtveidt.
Gorillas ranks second on my coolest games ever made right behind Oregon Trail.
Anyone here know what the math formula is to calculate monthly sales projections? I need it in order to finish the last question on Chapter 6 of my programming textbook. The whole program for that question is already done. I just don't know what the monthly sales forecast formula is. ](*,)
I'll second you there (on the Oregon Trail deal). The Apple // version rules ALL. I still play it sometimes for old time's sake on my Apple //c+. Yes, I am being completely serious. The Macintosh version was OK, but too graphical and hunting wasn't as cool as in the Apple // version; you couldn't walk around the forest and shoot different directions.
Where the f*ck did this thread come from? It just appeared out of the blue right before my eyes with 11 new messages. Now I know what stevek666 is talking about. To be honest, I just thought he was mental.
Around my office, I'm the boss. Anyone caught posting on PCENGINEFX.COM during work hours (like I sometimes do) would immediately get a raise and promoted. Sadly, no cool people work for me...
Yes, if it's as simple as what I think you're asking.The requirements for the question don't mention anything about specific days in a month. The months are just given standard numbers from 1-6 since the question is for a six month projection. Plus, there is the matter of growth rate percentages to deal with. For instance, if the minimum assumed growth rate is 7%, then I need to post 6 month sales forecasts with the added growth rate percentage. The growth rate goes up to a maximum of 4%. So therefore, 7% would go to 11% or 5% would go to 9%. I need a formula that disregards specific days in a month and takes into account growth rate percentages.
My entire job revolves around doing just that. That's right, I sit at a computer all day tabulating sales data and projecting sales and profit margins for the next week, month, and year. Then I devise new and illegal interesting ways to improve them. And in between when my boss isn't around I log on to www.pcenginefx.com/forums (http://www.pcenginefx.com/forums) and make fun of people.
(Sales MTD / Days of month that have passed) * number of days in month
For example, to project sales for June as of right now, and assuming my MTD sales are $50,000:
(50,000 / 3 (technically the 4th day isn't over so we won't count it) ) * 30 (30 days in June) = a projection of $500,000 for the month.
The requirements for the question don't mention anything about specific days in a month. The months are just given standard numbers from 1-6 since the question is for a six month projection. Plus, there is the matter of growth rate percentages to deal with. For instance, if the minimum assumed growth rate is 7%, then I need to post 6 month sales forecasts with the added growth rate percentage. The growth rate goes up to a maximum of 4%. So therefore, 7% would go to 11% or 5% would go to 9%. I need a formula that disregards specific days in a month and takes into account growth rate percentages.
Around my office, I'm the boss. Anyone caught posting on PCENGINEFX.COM during work hours (like I sometimes do) would immediately get a raise and promoted. Sadly, no cool people work for me...
Are you hiring? 'Cause I'd be willing to relocate for some of this easy money. :lol:
A paper products manufacturer needs a program to forecast its sales over a six-month period. To do so requires knowing the value of the sales growth rate and how the sales grow over that period. Write a program that asks the user to enter the minimum assumed growth rate (as a percent) and the sales for the current month. Assume a linear growth, that is, the sales for a month equals a fixed percent (the growth rate) over the previous month. The program should display, in a table, the projected sales for the minimum growth rate and for growth rates up to 4% greater than the minimum. The table should look like the following, if the user enters 7 for the minimum growth rate and 30000 for the current month's sales.
for (month_count = MONTH_START; month_count <= MONTH_END; month_count++)
{
projected_sales = (current_month_sales * (percent_count / PCT_CONVERSION) + current_month_sales);
current_month_sales = projected_sales;
printf(" %6.2lf", projected_sales);
}
The program outputs the projected sales results in "projected_sales" and then assigns the results into "current_month_sales". The output is displayed afterwards. Then, when "month_count" increments, "projected_sales" will be given a new value based on the newly assigned values in "current_month_sales". Does this work?
Better have all your shit done when I catch you on PCENGINEFX.COM.
f*ck that noise!
Better have all your shit done when I catch you on PCENGINEFX.COM.
f*ck that noise! I wanted to just roam pcenginefx.com all day and keep getting raises and promotions, but you'd actually expect me to work. I'd only take the Packaging Engineer job if I could put my package in a giant cardboard box with an expanded polystyrene insert (damn, that sounds dirty too).
"Hey, boss. Nat just posted another thread saying that 'Spaceballs 3: The search for the second movie' makes for a better sequel than 'Big Trouble in Little Korea!'"
Math's not my best subject either so you're not alone. :wink:
This is part of the chapter that requires the use of for loops to write your programs. *hint* *hint*
EDIT: I took your formulas to task and made this part of the loop body:Code: [Select]for (month_count = MONTH_START; month_count <= MONTH_END; month_count++)
The program outputs the projected sales results in "projected_sales" and then assigns the results into "current_month_sales". The output is displayed afterwards. Then, when "month_count" increments, "projected_sales" will be given a new value based on the newly assigned values in "current_month_sales". Does this work?
{
projected_sales = (current_month_sales * (percent_count / PCT_CONVERSION) + current_month_sales);
current_month_sales = projected_sales;
printf(" %6.2lf", projected_sales);
}
I'm hosting a sales meeting on Tuesday. I was going to get you some advice, but now I'm not gunna.
Nya nya-nya nya nya nyaaaaa. Yes even successful business types post on PCENGINEFX.COM!!!!!!
for (int_count = EVEN; int_count <= int_prompt - int_prompt; int_count++)
{
if (int_prompt / DIVISIBILITY)
printf("\nThe integer is divisible by 6.");
else
printf("\nThe integer is not divisible by 6.");
}
DIVISIBILITY has been predefined as "6". The result I get from the program has any number less than 6 be declared "not divisible" while any number equal to or greater than 6 declared "divisible". Is this correct? /* Prob 8-10
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#define ACCOUNT_LIMIT 0.00 /* The limit of the account between positive and negative balance */
main()
{
int choice; /* The user's selected choice */
float opening_balance, /* The opening account balance */
total_deposit, /* The total of all deposits */
deposit, /* The amount of the deposit */
total_check, /* The total of all checks */
check, /* The amount of the check */
total_withdrawal, /* The total of all withdrawals */
withdrawal, /* The amount of the withdrawal */
closing_balance; /* The closing account balance */
/* Prompt the user for the opening balance */
printf("Enter your opening account balance for the month: $");
scanf("%f", &opening_balance);
/* Display menu */
printf("\n(D)Deposit");
printf("\n(C)Check");
printf("\n(W)Withdrawal");
printf("\n(Q)Quit");
printf("\nMake your selection: ");
getchar();
choice = getchar();
/* Perform action based on choice */
do
{
if (choice == 'd' || choice == 'D')
{
printf("\nEnter the amount of the deposit: $");
scanf("%f", &deposit);
total_deposit += deposit;
}
else if (choice == 'c' || choice == 'C')
{
printf("\nEnter the amount of the check: $");
scanf("%f", &check);
total_check += check;
}
else if (choice == 'w' || choice == 'W')
{
printf("\nEnter the amount of the withdrawal: $");
scanf("%f", &withdrawal);
total_withdrawal += withdrawal;
}
else
printf("\nError. You must select the following: ");
printf("\n(D)Deposit");
printf("\n(C)Check");
printf("\n(W)Withdrawal");
printf("\n(Q)Quit");
printf("\nMake your selection: ");
getchar();
choice = getchar();
} while (!(choice == 'q' || choice == 'Q'));
/* Perform calculation */
closing_balance = opening_balance + total_deposit - total_withdrawal - total_check;
/* Check if account is overdrawn */
if (closing_balance < ACCOUNT_LIMIT)
{
printf("\nWARNING: Your account has been overdrawn by $%.2f", closing_balance + ACCOUNT_LIMIT);
printf("\n");
}
/* Display totals */
printf("\nOPENING BALANCE: $%.2f", opening_balance);
printf("\nTOTAL DEPOSIT: $%.2f", total_deposit);
printf("\nTOTAL WITHDRAWAL:$%.2f", total_withdrawal);
printf("\nTOTAL CHECKS: $%.2f", total_check);
printf("\n------------------------");
printf("\nCLOSING BALANCE: $%.2f", closing_balance);
}
Can you figure out why the if statement that checks for the overdrawn amount in the account won't appear in my program? Because I'm just positively baffled here. :?Thanks guys. :) I'll be back when I have another problem. :wink:
Thanks guys. :) I'll be back when I have another problem. :wink:
Fine with me. But as far as I know, I'm only one person. My name isn't Legion. :)
So that means you are not many?
GIVE US A KISS, DEAR!!
/* Prob 10-3
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#include <stdlib.h>
double Get_Opening_Balance(); /* Gets the user's opening account balance */
void Choice_Menu(); /* Displays a menu for choices */
void Validate_Choice(double); /* Validates the user's choice from the menu */
double Deposit(double, double); /* Gets the user's deposit amount */
double Withdrawal(double, double); /* Gets the user's withdrawal amount */
double Check(double, double); /* Gets the user's check amount */
void Display_Results(double, double, double, double, double); /* Displays all results and totals */
main()
{
double open_balance_amount; /* The user's opening account balance */
/* Call functions */
open_balance_amount = Get_Opening_Balance();
Choice_Menu();
Validate_Choice(open_balance_amount);
}
double Get_Opening_Balance()
{
double open_acct_balance; /* The user's opening account balance */
/* Prompt the user */
printf("\nEnter the opening account balance: $");
scanf("%lf", &open_acct_balance);
if (open_acct_balance < 0.00)
exit(0);
else
return open_acct_balance;
}
void Choice_Menu()
{
/* Display menu */
printf("\nSelect your choice: ");
printf("\n(D)Deposit");
printf("\n(C)Check");
printf("\n(W)Withdrawal");
printf("\n(Q)Quit");
printf("\n");
}
void Validate_Choice(double opening_balance_amt)
{
char choice; /* The choice entered by the user */
double total_deposit_amt, /* The total amount deposited */
total_withdrawal_amt, /* The total amount withdrawn */
deposited_amt, /* The amount deposited */
withdrawn_amt, /* The amount withdrawn */
total_check_amt, /* The total check amount */
check_amt, /* The check amount */
account_balance, /* The current account balance */
closing_balance_amt; /* The closing balance amount */
/* Initialization */
total_deposit_amt = 0.00;
total_withdrawal_amt = 0.00;
total_check_amt = 0.00;
account_balance = 0.00;
account_balance += opening_balance_amt;
/* Get choice */
getchar();
choice = getchar();
/* Validate choice */
while (choice != 'q' || choice != 'Q')
{
if (choice == 'd' || choice == 'D')
{
account_balance = Deposit(deposited_amt, account_balance);
total_deposit_amt = account_balance - opening_balance_amt - total_withdrawal_amt - total_check_amt;
}
else if (choice == 'w' || choice == 'W')
{
account_balance = Withdrawal(withdrawn_amt, account_balance);
total_withdrawal_amt = -(account_balance - opening_balance_amt - total_deposit_amt - total_check_amt);
}
else if (choice == 'c' || choice == 'C')
{
account_balance = Check(check_amt, account_balance);
total_check_amt = -(account_balance - opening_balance_amt - total_deposit_amt - total_withdrawal_amt);
}
else if (choice == 'q' || choice == 'Q')
{
closing_balance_amt = account_balance;
Display_Results(opening_balance_amt, total_deposit_amt, total_withdrawal_amt, total_check_amt, closing_balance_amt);
exit(0);
}
else
printf("\nError! You must enter the following choices listed on the menu.");
Choice_Menu();
getchar();
choice = getchar();
}
}
double Deposit(double deposit_amount, double pres_account)
{
/* Prompt the user */
printf("\nEnter the amount to be deposited: $");
scanf("%lf", &deposit_amount);
pres_account += deposit_amount;
return pres_account;
}
double Withdrawal(double withdrawal_amount, double present_account_balance)
{
/* Prompt the user */
printf("\nEnter the amount to be withdrawn: $");
scanf("%lf", &withdrawal_amount);
if (withdrawal_amount > present_account_balance)
{
printf("\nWarning! The amount you have withdrawn exceeds your current account balance.\n");
exit(1);
}
else
{
present_account_balance -= withdrawal_amount;
return present_account_balance;
}
}
double Check(double check_amount, double curr_account)
{
/* Prompt the user */
printf("\nEnter the check amount $");
scanf("%lf", &check_amount);
if (check_amount > curr_account)
{
printf("\nWarning! The check amount exceeds your current account balance.\n");
exit(1);
}
else
{
curr_account -= check_amount;
return curr_account;
}
}
void Display_Results(double opening_balance, double total_deposit, double total_withdrawal, double total_check, double closing_balance)
{
/* Display the results */
printf("\nOPENING BALANCE: $%.2lf", opening_balance);
printf("\nTOTAL AMOUNT DEPOSITED: $%.2lf", total_deposit);
printf("\nTOTAL AMOUNT WITHDRAWN: $%.2lf", total_withdrawal);
printf("\nTOTAL CHECK AMOUNT: $%.2lf", total_check);
printf("\n----------------------------------");
printf("\nCLOSING BALANCE: $%.2lf", closing_balance);
printf("\n");
}
First, if you're only dealing with whole dollars in this program change your data type for all your variables to long int, although it's probably not a big deal.
Next, without seeing your code, I'm going to guess you aren't initializing your variables. Depending how your program is set up this could make a big difference. I always believe it's good practice to initialize variables as you declare them regardless:
long int nat_rules = 0,
dark_fact_rules = 0,
we_all_rule = 0;
Without seeing your code it's going to be tough debugging the program further.... Try the initialization thing and if that doesn't work, post up your code.
Funny, I've heard the argument for not initializing your variables on declaration - for debugging reasons.
I'm sure there are merits to both "philosophies" but in my experience I've found it beneficial to initialize variables on declaration more often than not. As with everything, there are exceptions to the rule....
I totally agree. I had an associate once tell me there only one way to do things - insinuating that there is only one right way.
sorry dude, I know I'm lame. I still haven't even looked at it yet. Smile I'll get to it next time, I promise. But it always helps to post the code right away with your problem, cuz usually without code I can only speculate at what's going on.Sorry for the late reply. The problem I had involved finding a way to add up total deposits, withdrawals, and checks within my functions and then returning those totaled values to the Validate_Choice function. However, the problem always put out incorrect values. After re-reading the question, I found out that I wasn't supposed to total up my deposits, withdrawals, and checks within their own functions, but within Validate_Choice.
What was the problem, BTW?
Quote from: natsorry dude, I know I'm lame. I still haven't even looked at it yet. Smile I'll get to it next time, I promise. But it always helps to post the code right away with your problem, cuz usually without code I can only speculate at what's going on.
What was the problem, BTW?
Nat, chances are I'll be asking for help from my other friend over MSN when it comes to programming in the future. No offense, but I can't really wait a week or two for you to look at my program and tell me what's wrong. I need solutions, stat.
If I run into additional problems where I need to ask for further help, I'll let you know. :wink:
/* Prob 11-5
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#define HOMES 20 /* The maximum number of homes surveyed */
main()
{
float household_incomes[HOMES], /* The array to store the incomes */
maximum_income, /* The maximum income amount in the survey */
minimum_income, /* The minimum income amount in the survey */
average_income, /* The average income amount in the survey */
total_income, /* The total income amount from the survey */
median_income; /* The median income amount in the survey */
int income_count, /* Counts the incomes in the survey */
limit, /* Keeps track of how far to go on a pass */
pass, /* The number of the pass */
temp; /* Temporarily stores income amounts for sorting */
/* Initialization */
total_income = 0.00;
average_income = 0.00;
median_income = 0.00;
maximum_income = 0.00;
minimum_income = 1.00;
/* Prompt for incomes */
for (income_count = 0; income_count < HOMES; income_count++)
{
printf("\nEnter the income amount for home #%d: $", income_count + 1);
scanf("%f", &household_incomes[income_count]);
total_income += income_count + 1;
/* Determine maximum income */
if (household_incomes[income_count] > maximum_income)
maximum_income = household_incomes[income_count];
/* Determine minimum income */
if (household_incomes[income_count] < minimum_income)
minimum_income = household_incomes[income_count];
}
/* Calculate median and average income */
average_income = total_income / HOMES;
median_income = ((household_incomes[10] - 1) + (household_incomes[11] - 1)) / 2;
/* Sort the array in descending order */
limit = HOMES - 2;
for (pass = 1; pass <= HOMES - 1; pass++)
{
for (income_count = 0; income_count <= limit; income_count++)
if (household_incomes[income_count] < household_incomes[income_count + 1])
{
temp = household_incomes[income_count];
household_incomes[income_count] = household_incomes[income_count + 1];
household_incomes[income_count + 1] = temp;
}
--limit;
}
/* Display the sorted incomes */
printf("\nThe incomes in decreasing order are as follows:\n");
for (income_count = 0; income_count < HOMES; income_count++)
printf("$%.2f ", household_incomes[income_count]);
printf("\n");
/* Display the results */
printf("\nMAXIMUM INCOME: $%.2f", maximum_income);
printf("\nMINIMUM INCOME: $%.2f", minimum_income);
printf("\nAVERAGE INCOME: $%.2f", average_income);
printf("\nMEDIAN INCOME: $%.2f", median_income);
printf("\n");
}
/* Prob 11-9
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#define ALPHABET_TOTAL 25 /* The total number of letters in the alphabet */
main()
{
char text[ALPHABET_TOTAL], /* Text inputted by the user */
letter_count; /* array subscript for text */
/* The following declarations below are the array subscripts for the 'text' variable */
int a_count = 0,
b_count = 0,
c_count = 0,
d_count = 0,
e_count = 0,
f_count = 0,
g_count = 0,
h_count = 0,
i_count = 0,
j_count = 0,
k_count = 0,
l_count = 0,
m_count = 0,
n_count = 0,
o_count = 0,
p_count = 0,
q_count = 0,
r_count = 0,
s_count = 0,
t_count = 0,
u_count = 0,
v_count = 0,
w_count = 0,
x_count = 0,
y_count = 0,
z_count = 0;
/* Text input */
printf("\nPlease enter text. Terminate program by pressing enter: ");
text[letter_count] = getchar();
while (text[letter_count] = getchar() != EOF)
{
for (letter_count = 'a'; letter_count <= 'z'; letter_count++)
{
while (text[letter_count] = getchar() != '\n')
{
if (text[letter_count] == 'a')
++a_count;
if (text[letter_count] == 'b')
++b_count;
if (text[letter_count] == 'c')
++c_count;
if (text[letter_count] == 'd')
++d_count;
if (text[letter_count] == 'e')
++e_count;
if (text[letter_count] == 'f')
++f_count;
if (text[letter_count] == 'g')
++g_count;
if (text[letter_count] == 'h')
++h_count;
if (text[letter_count] == 'i')
++i_count;
if (text[letter_count] == 'j')
++j_count;
if (text[letter_count] == 'k')
++k_count;
if (text[letter_count] == 'l')
++l_count;
if (text[letter_count] == 'm')
++m_count;
if (text[letter_count] == 'n')
++n_count;
if (text[letter_count] == 'o')
++o_count;
if (text[letter_count] == 'p')
++p_count;
if (text[letter_count] == 'q')
++q_count;
if (text[letter_count] == 'r')
++r_count;
if (text[letter_count] == 's')
++s_count;
if (text[letter_count] == 't')
++t_count;
if (text[letter_count] == 'u')
++u_count;
if (text[letter_count] == 'v')
++v_count;
if (text[letter_count] == 'w')
++w_count;
if (text[letter_count] == 'x')
++x_count;
if (text[letter_count] == 'y')
++y_count;
if (text[letter_count] == 'z')
++z_count;
}
}
for (letter_count = 'A'; letter_count <= 'Z'; letter_count++)
{
while (text[letter_count] = getchar() != '\n')
{
if (text[letter_count] == 'A')
++a_count;
if (text[letter_count] == 'B')
++b_count;
if (text[letter_count] == 'C')
++c_count;
if (text[letter_count] == 'D')
++d_count;
if (text[letter_count] == 'E')
++e_count;
if (text[letter_count] == 'F')
++f_count;
if (text[letter_count] == 'G')
++g_count;
if (text[letter_count] == 'H')
++h_count;
if (text[letter_count] == 'I')
++i_count;
if (text[letter_count] == 'J')
++j_count;
if (text[letter_count] == 'K')
++k_count;
if (text[letter_count] == 'L')
++l_count;
if (text[letter_count] == 'M')
++m_count;
if (text[letter_count] == 'N')
++n_count;
if (text[letter_count] == 'O')
++o_count;
if (text[letter_count] == 'P')
++p_count;
if (text[letter_count] == 'Q')
++q_count;
if (text[letter_count] == 'R')
++r_count;
if (text[letter_count] == 'S')
++s_count;
if (text[letter_count] == 'T')
++t_count;
if (text[letter_count] == 'U')
++u_count;
if (text[letter_count] == 'V')
++v_count;
if (text[letter_count] == 'W')
++w_count;
if (text[letter_count] == 'X')
++x_count;
if (text[letter_count] == 'Y')
++y_count;
if (text[letter_count] == 'Z')
++z_count;
}
}
}
printf("\ntotal a or A: %d", a_count);
printf("\ntotal b or B: %d", b_count);
printf("\ntotal c or C: %d", c_count);
printf("\ntotal d or D: %d", d_count);
printf("\ntotal e or E: %d", e_count);
printf("\ntotal f or F: %d", f_count);
printf("\ntotal g or G: %d", g_count);
printf("\ntotal h or H: %d", h_count);
printf("\ntotal i or I: %d", i_count);
printf("\ntotal j or J: %d", j_count);
printf("\ntotal k or K: %d", k_count);
printf("\ntotal l or L: %d", l_count);
printf("\ntotal m or M: %d", m_count);
printf("\ntotal n or N: %d", n_count);
printf("\ntotal o or O: %d", o_count);
printf("\ntotal p or P: %d", p_count);
printf("\ntotal q or Q: %d", q_count);
printf("\ntotal r or R: %d", r_count);
printf("\ntotal s or S: %d", s_count);
printf("\ntotal t or T: %d", t_count);
printf("\ntotal u or U: %d", u_count);
printf("\ntotal v or V: %d", v_count);
printf("\ntotal w or W: %d", w_count);
printf("\ntotal x or X: %d", x_count);
printf("\ntotal y or Y: %d", y_count);
printf("\ntotal z or Z: %d", z_count);
}
unsigned char get_char;
unsigned int count_array[25];
//note: I usually make my arrays a little bigger then the space I need incase I overwrite another area of memory with an out of bounds pointer
.
.
.
get_char|=0x60;
That will convert all alphabetical characters to lower case. Use get_char&=0x5F to convert it to upper case.
if( (get_char>0x40 && get_char<0x5b) || (get_char>0x60 && get_char<0x7b) )
{
get_char&=0x5F; //convert to lowercase
get_char-=0x41; //subtract offset to beginning char starts at 0
count_array[get_char]++; //use the char as an index into your array and increment that specific usage
} else {
//error
}
for(int i=0,i<25,i++)
{
printf("\n total %s or %s: %d", (i + 0x41), (i + 0x61), count_array[i]);
}
while (text[letter_count] = getchar() != EOF)
{
letter_count++;
}
/* Prob 11-9
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#include <stdlib.h>
#define ALPHABET_TOTAL 25 /* The total number of letters in the alphabet */
main()
{
unsigned int text[ALPHABET_TOTAL]; /* Array to store all letter instances of the alphabet */
int letter_count, /* Counts the letter instances in the text input */
char_count = 0; /* Counts the letters in the text input */
/* Text input */
printf("\nPlease enter text. Terminate program by pressing enter: ");
text[char_count] = getchar();
while (text[char_count] = getchar() != EOF)
{
if (text[char_count] = getchar() == EOF)
break;
else
{
++char_count;
while (text[char_count] = getchar() != '\n')
{
if (text[char_count] = getchar() == '\n')
break;
else
++char_count;
}
}
}
for (letter_count = 0; letter_count < ALPHABET_TOTAL; letter_count++)
{
printf("\n total %c or %c: %d", (char_count + 0x41), (char_count + 0x61), text[char_count]);
if((getchar() > 0x40 && getchar() < 0x5b) || (getchar() > 0x60 && getchar() < 0x7b))
{
text[char_count] &= 0x5F;
text[char_count] -= 0x41;
text[char_count]++;
}
else
{
printf("\nError.");
exit(1);
}
}
}
The program is really stubborn with that EOF statement. I've tried inserting a couple of break statements to break the loop but that hasn't worked. I also tried using a different character count variable. What am I doing wrong now? :(
/* Prob 11-9
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#include <stdlib.h>
#define ALPHABET_TOTAL 25 /* The total number of letters in the alphabet */
main()
{
int text[ALPHABET_TOTAL] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
alpha_count, /* Counts the letters in the alphabet */
char_count = 0, /* Counts the instances of each letter */
letter_count = 0; /* Counts the letters in the text input */
char text_input; /* The text inputted by the user */
/* Text input */
printf("\nPlease enter text. Terminate program by pressing Ctrl+Z: ");
text_input = getchar();
/* Increment counter if not End Of File */
while (text_input = getchar() != EOF)
++letter_count;
/* Display the results */
for (alpha_count = 65; alpha_count <= 90; alpha_count++)
{
if (getchar() == text[alpha_count] || getchar() == text[alpha_count + 32])
char_count++;
printf("\nTotal %c or %c: %d", alpha_count, alpha_count + 32, char_count);
}
}
I haven't used getche() because my textbook doesn't cover that and I haven't seen anything good come out of that when I tried it in my program. I declared a couple of variables called "alpha_count" to count all the letters in the alphabet and "char_count" to increment the letter instances in my block of text./* Prob 11-9
* Created by Yuriy Mokriy
*/
#include <stdio.h>
#define ALPHABET_TOTAL 26 /* The total number of letters in the alphabet */
main()
{
int text[ALPHABET_TOTAL] = {0}, /* Array sized 26, acting as counters for all characters 'a' .. 'z' (case insensitive) */
text_input, /* Reads in the text input as characters */
ASCII_count, /* The ASCII numerical representation of letters in the alphabet */
alpha; /* boolean "flag" which turns to 0 (false) in case of a non-alpha character */
/* Initialization */
text_input = 0;
ASCII_count = 0;
alpha = 0;
/* Get input */
printf("\nPlease enter text. Terminate program using Ctrl+Z: ");
while( text_input != EOF )
{
alpha = 1;
text_input = getchar();
/* If input is alphabetical, convert to a number 0-25 so that it can be used as an array index locator */
if(text_input >= 'a' && text_input <= 'z')
text_input -= 'a';
else if(text_input >= 'A' && text_input <= 'Z')
text_input -= 'A';
/* Non-alphabetical character, set the alpha flag to false */
else
alpha = 0;
/* Increment the appropriate counter in the text array as long as the character is alphabetical */
if(alpha)
text[text_input]++;
}
/* Display results */
for (ASCII_count; ASCII_count <= 25; ASCII_count++)
printf("\nTotal %c or %c: %d", ASCII_count + 'a', ASCII_count + 'A', text[ASCII_count]);
}