C++ :: Program To Display Percentage Of Calories Come From Fat
Mar 18, 2013
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.
View 4 Replies
ADVERTISEMENT
Feb 10, 2013
How to compare two files(two texts documents) and display their similarity percentage by using C++?
View 10 Replies
View Related
Feb 18, 2015
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.
View 6 Replies
View Related
Feb 11, 2014
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>
[Code].....
View 2 Replies
View Related
Mar 5, 2013
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";
[Code] .....
Error:
1>------ Build started: Project: HOMEWORK5, Configuration: Debug Win32 ------
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:UsersWORKHOMEWORK5DebugHOMEWO… : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
View 4 Replies
View Related
Oct 28, 2013
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;
[Code] .....
View 5 Replies
View Related
Mar 7, 2013
#include <iostream>
#include <iomanip>
#include <math.h>
[Code].....
I AM HAVING TROUBLE CALCULATING THE PERCENTAGE. I HAVE TO CALCULATE THE AMOUNT OF MONEY FOR 6 YEARS.
View 1 Replies
View Related
May 28, 2013
Below is the code of a program using classes and functions ,, my float function doesn't show answer in fractions ,, show something else...
#include <iostream>
using namespace std;
class khan{
public:
void print(){
cout<<"welcome to the online Addition System!!!" <<"
[Code] ...
View 6 Replies
View Related
Jun 19, 2014
I want to update a file but I want to show the percentage when it is being updated. How can I do this? Do I need to use threads?
View 2 Replies
View Related
Mar 1, 2014
Why does my progressbar percentage text disapear when progressbar starts loading?? Am I missing out anything?
int percent = (int)(((double)(progressBar1.Value - progressBar1.Minimum) /
(double)(progressBar1.Maximum - progressBar1.Minimum)) * 100);
using (Graphics gr = progressBar1.CreateGraphics()) {
gr.DrawString(percent.ToString() + "%",
SystemFonts.DefaultFont,
[Code] ....
View 1 Replies
View Related
Jan 2, 2014
I am trying to get this program to accept two inputs Student number and grade and validate them both
However the program skips over the student number
Code attached AssignmentProgram.c
View 1 Replies
View Related
Apr 15, 2014
Program calculates cost from wholesale to final cost with percentage markup!
#include <iostream>
using namespace std;
int calculate_retial(int,int);
int main () {
int wholesale;
int markup;
int cost;
[Code] ....
View 5 Replies
View Related
Nov 18, 2014
exercise in c: write a program which calculates % of even numbers entered by a user in an array;
1) check if user hasn't entered float value; if has issue warning;
2) give the option for user to press "stop" to exit program any time.
int c,sk[100],i,sum1=0, sum2=0, rel;
printf ("How many numbers will you enter?
");
scanf ("%d", &c);
printf ("Enter %d numbers (to exit program press - stop)
", c);
[Code] ....
View 1 Replies
View Related
Feb 10, 2015
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));
[Code] .....
View 2 Replies
View Related
Jun 21, 2014
C++: write a c++ program that will display your name, address and age..
View 3 Replies
View Related
Jan 23, 2014
i wrote this program to display even number from 100-200. But visual c gives me this error with undeling the "a" in if statement. Error1error C2106: '=' : left operand must be l-value
#include<iostream>
#include<conio.h>
using namespace std;
void main(){
for(int a=100;a<200;a++){
if(a%2=0)
cout<<a<<endl;
}
_getch();
}
View 1 Replies
View Related
Feb 8, 2014
I have to write a program to display multiplication tables. I have written the following code:
Code:
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
[Code] ....
View 2 Replies
View Related
Feb 21, 2013
Write a program that displays n depth * pyramid.
For example,Input: 4
Output:
*
***
*****
*******
This is what i have so far but it not giving me what i want.
#include <iostream>
using namespace std;
int main() {
int star;
int count=1;
cout<<"Enter the number: ";
cin>>star;
[Code] ....
View 1 Replies
View Related
Oct 4, 2014
This is a program that display prime numbers from 1 to 100. it has problem linking when i run the program.
#include <iostream>
class Prime {
public:
int PrimeNo();
int Display();
};
// class Prime number
int Prime::PrimeNo()
[Code] ....
View 3 Replies
View Related
Feb 25, 2014
Write a program that displays the first 40 Fibonacci numbers. A Fibonacci number is created by add the previous two, with the first two always being 0 and 1. A partial sequence is as follows:
0, 1, 1, 2, 3, 5, 8, 13, 21,….
Your table must display 6 numbers per row and use a spacing of 10 for each number. Don’t forget to include the header file “iomanip” at the top and use “setw()”. You will need to turn in an algorithm, source code and output.
Here is what i have but i get errors!
#include <iostream>
using namespace std; {
int FirstNumber = 0;
int SecondNumber = 1;
int NumberOfNumbers = 2;
int NewNumber;
[Code] .....
View 3 Replies
View Related
Feb 14, 2013
I'm trying to display the AM/PM on my program:
Also is there a way to display the time only instead of the date? How will i change the program to display the time in standard 12 hours, instead of 24 hours?
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
time_t tim;
time(&tim);
cout << ctime(&tim);
}
View 1 Replies
View Related
Apr 28, 2015
IM trying to make a simple program that will display morse code. Ex if you type 0 print should be (-----) and all the way up to 5. The problem is though that all printf displays all the numbers and not executing only the assigned variable.
#include<stdio.h>
int main(void) {
int a , b , c , d , e, f, x;
a = 0;
b = 1;
c = 2;
d = 3;
e = 4;
f = 5;
x = 6;
[Code] ....
View 4 Replies
View Related
Mar 23, 2014
I decided to create a simple program to display a menu with options, while that is easy enough I had some difficulty when selecting an option that has options inside which also has an option again. While I had many issues in the past I'm finally finished with it and it works fine, but being new to programming and not knowing various other methods available.
Code:
//:::::::::::::::::::::Simple Menu Program::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#include <iostream>
#include <string>
//function prototypes
[Code] .....
View 1 Replies
View Related
Dec 28, 2013
Constructing this right aligned half pyramid? The code I had so far is right aligned and they're not in numbers
Write a program that receives one positive integer and display
_________ _ 1
________ 4 2
_______9 6 3
___16 12 8 4
25 20 15 10 5
when the user key in 5.PS: ignore the line
View 3 Replies
View Related
Nov 4, 2013
SO Im supposed to write a program that uses arrays to calculate the sum and display it. I keep getting the error that says the sum has to be initialized.
#include <iostream>
using namespace std;
//Function prototype
int sumArray(int);
const int NUM_ELEMENTS = 5;
[Code] .....
View 1 Replies
View Related
Dec 9, 2013
How do i display the output ? This program only saves the output to "gpa.txt" I want it to also display the output to cmd.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
const int SIZE = 10;
[Code] ....
View 1 Replies
View Related