void reverse(char *in, int isize) { char t = 0; for( int a = 0; a < isize / 2; a++ ) { t = in[a]; in[a] = in[(isize - 1) - a]; in[(isize - 1) - a] = t; [Code] .....
s: float:123456 s:123456
The function i made is working fine, exacly how cout << float is working. The problem is i think my function is not really effective. By that i mean my function is doing alot of useless stuff to do what i want and there have to be a better way.
The rule is that you can not use other functions, only playing with loops and operators.
I need to create a main function with a one dimension dynamic array with float data type. The total number of array elements must be controlled by a user input from the keyboard. Test data is three different lengths 3,6,9 of the array. The lengths have to be set up at run time from users input. I understand how to create dynamic array but not where the user inputs the length of the array. How would I implement this?
Write a program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, so:
(Calories from fat) = (fat grams) * 9
The percentage of calories from fat can be calculated as:
(Calories from fat) / (total calories)
Extend as follow
1. The user first enters from a menu whether it is breakfast (B or b), lunch (L or l) or dinner (D or d). Use character and process by a switch. 2. The threshold for low calorie is different, for breakfast 10%, lunch 20%, dinner 30% (this value has to be assigned to some threshold variable in the above switch). 3. Include validation of menu choice. 4. In case any validation fails, display detailed error and exit the program by calling return 1 or return EXIT_FAILURE 5. Display the % from fat with one decimal digit.
Example 1: What you have to eat: B - breakfast L - lunch D - dinner What you have: C Error: C is not a valid menu choice
Example 2: What you have to eat: B - breakfast L - lunch D - dinner What you have: L How many calories: 600 How many grams of fat: 10 Your food has 15.0% calories from fat It is a low calories food
Process the menu in a switch, setting the threshold as either 10, 20, or 30%. The rest of the program will be the same regardless what was the menu choice.
Incremental development: first do the textbook problem without input validation, then extend with validation, then extend for the additional parts.
What I need to do Is constantly read the cpu percentage and display it to a textbox, but the issue is I am using the windows form not the console so I cant use a while loop. I think my best bet is to use an event, but I am not sure how.
I am using codeblocks for school and I am trying to create a program to calculate a percentage for commission and a bonus. I have tried using a decimal for percentage, int and floats with casting. Every time it I try it displays 0 or just the bonus. I even took and did a test page. My head is about to pop.
Write an algorithm that can be used to calculate the commission earned in a real estate transaction. The chart below describes the formulas used to calculate the commission.
Sales Price Commission Less than $100,000 5% of Sales Price $100,000 to $300,000 $5,000 + 10% of Sales Price over $100,000 More than $300,000 $25,000 + 15% of Sales Price over $300,000
// Commission and Bonuses. #include <iostream> #include <iomanip>
Write a program that calculates the total grade for N classroom exercises as a percentage. The user to input the value for N followed by each of the N scores and totals. Calculate the overall percentage (sum of the total points earned divided by the total point possible) and output it as a percentage. Sample input and output it as a percentage. Sample input and output is shown below.
How many exercises to input? score1: 10 total points possible: 10 score2: 7 total points possible: 12 score3: 5 total points possible: 8
Code: # include <iostream> using namespace std; int main () { double N=0, score, total, totalScore=0, totalGrade=0, GRADE; cout<<"How many excersices will be scored?/n";
I'm having trouble getting the program to calculate the percentage of times it flipped either heads versus tails. I realize what I currently have doesn't work because above I initialized heads and tails by giving them values of 0, but I'm unsure of how to fix it.
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main () { srand(time(0));
I am trying to code and compile a program that requests a uses to first inpu the number of sides they wish for a dice to have and secondly input the number of dice throws they would like to calculate the value for. The program will print an error message and default the number of sides the dice has to 5 if the number entered is below 4. Finally it will print out a percentage figure for each value that results from all the the dice rolls.
I have attached my header, driver and class files below along with accompanying error messages below them
// file name Exercise.cpp #include <iostream> #include "Die.h" using namespace std; int main() // the main program begins here { char restart = 'y'; // declare variables double numRolls = 0.0; int diceTot = 0;
determining if a value entered in loop is an odd or even number. Also, the value can't be int because it may be a decimal value(therefore i cant use the if(x%==0).
I need to replace the if(value%2 ==0) else num_even++ statement in my code with something else that will work with float to determine odd vs even.
#include <iostream> using namespace std; int main() { int num_values; float sum_values = 0; int num_neg_values = 0; int num_pos_values = 0;
N=1st number M=2nd number(accrding to my prof we will name it N and M ctr= increment of factorial of N, ctr2= increment of factorial of (N-M)
the problem is when i got the factorial of N / factorial of (N-M) i need to get the last non zero digit. so i use mod if it has zero in it. but mod can be only used with an int value. and when i change it to int value, the value of fact1 which is a float change
I am looking for a math/big num library, that allows me to convert 32/64/80 bot float numbers to string and vice versa.
Precision & accuracy is of importance here, and since this is an IEEE standard, i have high hopes that there are libraries for this out there, which would save me the hassle of trying to implement this myself...
I am working from my "ansi c" book by steven lawlor, page 73 program 2. write a program that accepts two numbers from the keyboard and prints the following information.
variables first second execution First number ? 7 Second number ? 2 the second goes into the first 3 times with a remainder of 1. the quotient is 3.5.
Code: #include <stdio.h> main() { int first, second; scanf(" %1i %1i", &first, &second); printf("First number ? %1i
[Code] ....
//I included this as I had some error message come up // before, not sure if this is correct though? } it shows what is expected but I cant get the 3.5.
I have tried %f and variations of width/precision but still not luck. Also, when I click on the application and put in the variables I press enter, the program executes and disappears so I cant see the result. how do I get the program to stay up until I want to get rid of it?
I just checking but confused with float. in that code same size int, and same type double are working but float showing nothing in printf..why?? i'm using GCC compiler int 32bit win7 os