C :: Design Algorithm Using Flowchart Or Pseudo Code To Prompt User For Series Of Positive Integer Value
Oct 26, 2014
Design an algorithm using flowchart or pseudo-code to prompt the user for a series of positive integer values. Calculate the average of these values and display the average at the end of the program. Assume that the user types the sentinel value -1 to indicate end of data entry.
Sample input-output:
Enter a positive integer (-1 to end) : 5
Enter a positive integer (-1 to end) : 7
Enter a positive integer (-1 to end) : 6
Enter a positive integer (-1 to end) : -1
The average value is: 6
I searched online and found out this solution however it is only for three numbers.Is there any way of modifying this to include the sum of x numbers / number of x(integers) to find the average?
I'm expected to write a c program for this question :
Using these header files #include <stdio.h> #include <conio.h>
Question : Write a program that will prompt the user to enter an integer value and a character code to indicate whether they want to do a Kilogram to Pounds conversion (A) or a Pounds to Kilogram (B) conversion. Note that 1 kg = 2.2 pounds. The program should then do the necessary conversion indicated by the code and display the newly converted value to the screen.
Write a program asks the user for a positive integer value and then prints out all perfect numbers from 1 to that positive integer. I have been trying for some time, i found a way to check if its a perfect number or not but could not find a way to prints out all perfect numbers from 1 to that positive integer. I am here so far.
#include<iostream> #include<iomanip> using namespace std; int main(){ int n,i=1,sum=0; cout<<"Enter a number: ";
Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.
OUTPUT must be:
n = 5 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0
if n = 6 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0 6==5==4==3==2==1==0
I'm doing a practice problem where I need to read pseudo code and understand what it does.
For this code, I believe it will move the robot forward while i<650, so it moves it forward for 650 steps in total. Then it sets the motors to 0 when it's finished.
Code: while(i<650) { rotateCW(2); rotateCCW(1); Delay1KTCYx(50); i++; LATD=0x00; //Set all Port D to 0 }
This code I'm having the most trouble with. So while(1) the pot(potentiometer) read's the ADC. Then it scales the adc, not 100% sure what the +20 and *.22 mean, I think it has to do with binary conversions?
Now it sets pin 1 of port 1 to 0, delays based on pot above, and sets it back to 1, and delays again. I assume something to do with controlling motor speed based on the potentiometer.
Code: void main(void){TRISD = 0x00; // Setting port D to outputs LATDbits.LATD0 = 1; // Setting bit 0 of port D to 1 while(1) { pot = readADC(); pot = pot * 0.2297 + 20;
[Code] ......
My best guess is: The car moves forward 400 steps, stop, turn right for 230 steps, stop. At this point it would begin moving straight, and it would turn left/right as needed to keep the robot in the center of the track.
Code: void main(void) { for(i=0;i<400;i++) { rotateCW(2,motor); //Rotate motor two (one step) rotateCCW(1,motor); //Rotate motor one (one step) Delay1KTCYx(50);
I have finished writing the code for the following program. I have concerns with the pseudo-code that I have written and the flow chart seems really complicated. I dont know how to build it. Here is the question:
An Internet service provider has three different subscription packages for its customers: Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour. Package B: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour. Package C: For $19.95 per month unlimited access is provided.
Write a program that calculates a customer s monthly bill. It should ask which package the customer has purchased and how many hours were used. It should then display the total amount due.
Input Validation: Be sure the user only selects package A, B, or C. Also, the number of hours used in a month cannot exceed 744
Here is my program: #include <iostream> using namespace std; int main() { char package; int hours;
[code]....
What should be my pseudocode and flowchart ? Can i copy and paste my pseudocode here ?
Set found to false. Set position to -1. Set index to 0. While found is false and index < number of elements If list[index] is equal to search value found = true. position = index. End If Add 1 to index. End While. Return position
You pros are once newbies like us. Hoped you might take a little time sharing your expertise. Got freaked out when our teacher gave us this activity, where she haven't taught this to us yet. So this is the activity (LOOPING) :
Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.
OUTPUT must be:
n = 5 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0
if n = 6 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0 6==5==4==3==2==1==0
I have an embedded microcontroller system communicating with a similar system by radio. The api for the radio requires data to be transmitted as an unsigned char array. It will always transmit a positive integer in the range 0 to 255.When I receive the data I am having difficult in extracting this positive integer.
Code: unsigned char rxData[4]={'1','2','3',''}; int inVal=0;
//want to assign inVal whatever number was transmitted
E.g. 123
I've been at this for a week and have tried at least 10 different approaches including the use of the atoi(), copying the absolute value of each element of rxData into another char array, reinterpret_cast, and others.
My question is are there various ways that I can approach this program. I.e. do I have to use switch statements?
/* NumToTxt Creates the appropriate word form of any positive integer up to 999999 */
#include <iostream> using namespace std; //represents the largest array size for the user entered number const int MAXNUMARRAY = 6; /*represents the largest number that can be entered + 1. Used to calculate the first number used to truncate the user entered number and to display an error message to the user that tells the user the largest number that the program will accept. */ const int BIGGESTNUMBER = 1000000;
convert a positive integer code into its english name equivalent for digit. A valid code is of size between four (4) to six (6) digits inclusive. A zero is not allowed in the code.
example : if the input is 234056 the output is : INVALID CODE (PRESENCE OF ZERO) if the input is 23456 the output is : TWO THREE FOUR FIVE SIX if the input is 9349 the output is : NINE THREE FOUR NINE if the input is 245 the output is : INVALID CODE (3 DIGITS) if the input is 2344567 the output is : INVALID CODE (7 DIGITS)
step 1 : input code step 2 : count the number of digits in the code step 3 : if there is a zero in the code, "INVALID CODE (PRESENCE OF ZERO)" go to step 4 step 4 : if number of digits is mode or equal than 4 and less or equal than 6, go to step 5 else display the following message "INVALID CODE (<number of digits> DIGITS) step 5 : call a function called digit_name to convert each digit into its equivalent english name. display the result step 6 : print the digits in reverse order eg; if input is 13453, reverse order is 35431
Here is a simple drinks machine programm. It basically consists in the user selecting a drink that it's presented, if the user selects correctly the number representing a certain drink, the machine shows the user what was the drink he selected, after his choise the machine asks for money insertion, if the user inserts the incorrect amount of money, the machine shows an error saying that user need to insert the correct amount of money.
My problem is that, if the user selects a different number other than those presentend, the machine displays an error saying that he needs to choose a valid drink, but i can't find a way to reprompt the user again after the error has been displayed. here's the code.
// ***Drinkins Machine*** by Roxmate #include <iostream> #include <cstdlib> using namespace std; int main() { // initializes the variables coca, fanta, iced and drink to be used in switch function,so that the user can choose what drink he wants. int coca = 1;
The problem deals with writing a program to geta series of integers from a user and storing those values into an array. Then use a function called selection_sort, when given an array with n elements, the function must sort the array from smallest to largest values.
I have code, and im trying to get it to compile but im getting these implicit declaration errors and conflicting types. Here is my code and the compiler errors.
Code: Compilation started at Sun Feb 10 20:14:48
gcc -Wall -o ex9-1 ex9-1.c ex9-1.c: In function 'main': ex9-1.c:16:5: warning: implicit declaration of function 'selection_sort' [-Wimplicit-function-declaration] ex9-1.c:20:2: warning: implicit declaration of function 'prinf' [-Wimplicit-function-declaration] ex9-1.c: At top level:
[Code] ...
Compilation exited abnormally with code 1 at Sun Feb 10 20:14:49
Code: #include <stdio.h> int main(void) { int a[100], i, j, N; printf("How many numbers will you be entering: "); scanf("%d", &N);
I was asked to write a code that has the user input a number and then the computer calculates it for the Fibonacci series. The output should be separated by commas and a period should follow the last number. Ex. 1,2,3,4,5. <---period
I can't seem to get the period at the end. I have the commas and everything else. Here is my code:
#include "stdafx.h" #include <iostream> using namespace std; int main() { double num;
cout << "How many Fibonacci numbers do you want to display?";