Visual C++ :: Prompt User To Enter Integer Value And Character Code To Indicate Conversion

Sep 14, 2013

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.

View 1 Replies


ADVERTISEMENT

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?

View 5 Replies View Related

Visual C++ :: Letting User Enter A Character On Specific Line And Place?

Aug 8, 2014

How can I create in my C++ program so a user can paste a text and then choose a character on specific line and place?. The above thing isn't that important. I just want to place a character on a specific line and place.

I mean something like this:

Enter a character:

You choosed " / "

On which line do want the character?

You choosed "Line 1 and 2"

Where do you want the the to appear on the line? (left or right)

You choose left.

Results:

Line 1. / hello

Line 2. / hello

View 8 Replies View Related

C++ :: Prompt A User To Enter M For Male Or F For Female

Dec 24, 2014

I am simply trying to prompt a user to enter M for Male or F for Female. However, when I test run the program (what I've got so far below), any letter inputted is accepted and continues the program..?

#include <iostream>
using namespace std;
int main() {
char gender;
int maleBodyWeight;

[Code] .....

View 2 Replies View Related

C++ :: Prompt User To Enter Domain Name - Return Resolved IP Address

Feb 16, 2013

This is a winsock program designed to prompt the user to enter a domain name. The program is then supposed to return to the user a resolved ip address of that domain name. The user should also be able to enter an IP address and receive back a domain name.

While the program prompts the user to enter the domain name, all that is ever returned is error#:0

HTML Code:
// Declare and initialize variables
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")
#include <iostream>
int main(int argc, char **argv) {
hostent* remoteHost;

[Code] ....

View 12 Replies View Related

C :: Prompt User For Input And Display Character In Every Line

Mar 17, 2013

I am having problems printing "->" on the beginning of each line, im trying to do it as a loop and ending it when the user types "q". also i would like to know how to ignore text from the user when the input begings with a specific character. heres what ive done so far, and not currrently working as expected.

Code:
#include <stdio.h>
int main (void) {
char prompt;
printf("~~~ FRACTION CALCULATOR ~~~

[Code] ....

View 1 Replies View Related

C++ :: Program That Asks User To Prompt Integer Number

Nov 18, 2013

Write a program that asks the user to prompt an Integer number and then test whether it is Palindrome Numbers or not.

The following are Palindrome numbers:
1.22
2.333
3.67876
4.44444
5.123454321

View 8 Replies View Related

C++ :: Write A Program That Prompts The User To Enter Integer?

Nov 8, 2013

Write a program that prompts the user to enter an integer and then displays that integer as a product of its primes and if it is a prime then it should say so? Above is the question I have been given

#include <iostream>
#include <vector>
using namespace std;
int main () {
int num, result;
cout << "Enter A Number " << endl;
system ("pause");
return 0;
}

This is what I have so far, do I have to use a for loop, a while loop or a do loop,

View 7 Replies View Related

Visual C++ :: Allow User To Enter A Value As C String In Certain Form

Oct 14, 2013

My program was to allow the user to enter a value as a C string in the form: xxx,xxx,xxx,xxx,xxx.xx, where x can be any digit. Well, so far here is my attempt. I think the question is, would I have to implement a switch statement for the digits, the comma, and the decimal, so that when a user inputs, let say 52,000.00 the switch statements would read the 1st digit, checks for decimals/commas and if not, proceed to read 2nd digit, and repeat?

Code:
#include <iostream>
#include <string>
int main() {
using namespace std;
char buffer[256];
char tempBuff[256] = {'

[Code] ....

View 3 Replies View Related

Visual C++ :: Create A File That Ask The User To Enter His Info

Nov 9, 2014

What I want to do is create a file that will ask the user to enter his info,n then store it in a text file The screen will ask the user if he wants to update his info. if he says yes then the screen will be cleared and the old info will be printed on the screen. The user will enter his new info that will be stored in a new file. My problem is that once the user finishes entering his input the program just closes D: and the rest of the program won't run.

Code:

int main()
{
string ans;
ofstream Xfile("original.txt");
cout <<"Enter your name and address please"<<endl;
cout<<"Press Ctrl+Z+Enter when you are done"<<endl;
string name_and_street;

[Code]...

View 3 Replies View Related

C++ :: Temperature Conversion Is Coming Up Wrong When Enter In Input

Feb 1, 2015

How would you be able to show both outputs celsius and Fahrenheit and my temperature conversion is coming up wrong when i enter in the input. here is my code...

#include<iostream>
using namespace std;
int main(){
double celsius;
double fahrenheit;

[code].....

View 1 Replies View Related

Visual C++ :: Write A Program Where The User Will Input Integer Numbers?

Oct 21, 2014

I have to write a program where the user will input integer numbers. How many numbers they enter is unknown, therefor you should use a repetition structure for the input. When the user is done, they will enter -1 to exit.

Create a dynamic array if the size=2( the initial size must be 2) Repeat until user enters -1.

I have to do this without using vectors.

This is what i have, I cannot figure out what to put in main. I was thinking of a do-while?

Code:
#include <iostream>
using namespace std;
void resize(int *[], int);
int main() {
int *listDyn;
int size=2;

[code].....

View 5 Replies View Related

Visual C++ :: Ask User To Enter A Sentence And Then A Word To Be Searched For In Sentence

Oct 9, 2013

I am trying to write a program that ask the user to enter a sentence and then a word to be searched for in the sentence. The program must then search for the word in the sentence in a loop and continue to output each place the word is found. For example if the sentence is : I like pickles, pickles, pickles

and you searched for pickles it would return pickles found at 7, pickles found at 16, pickles found at 25.

I am having trouble writing the equation to make the find keep searching after each occurrence of the word being searched. Here is the code I have so far

HTML Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string paragraph;

[Code] ....

View 5 Replies View Related

C :: Float / Integer Conversion

Oct 14, 2013

why does the following code output "0.000000" instead of "1.000000"?

Code:

#include <stdio.h>
int main(void) {
int x=3, y=2;
printf("3/2 is %f
", x/y);
return 0;
}

the code was compiled and run using gcc 4.4.7 and glibc 2.17 on linux kernal 2.6.32 running on a PC with an intel i5-2500k cpu(sandy bridge)

View 8 Replies View Related

C++ :: Loop Conversion Integer To Binary

Aug 9, 2013

This program is basically working. I'm very knew to C++, so basically I need instructions as if you were explaining this to your grandma. I need this to loop but how to incorporate one. Basic code (while loops). Here is what I've done so far.

#include <iostream>
using namespace std;
int main () {
int i, c, k;
cout << "Please enter a number to convert: ";
cin >> i;

[Code] ....

View 4 Replies View Related

C Sharp :: Integer To Boolean Conversion?

Nov 20, 2014

ive written a simple code but throws an error in C#, why is this happen.

    bool inputValue = Convert.ToBoolean(Console.ReadLine());
        Console.WriteLine(inputvalue);
        Console.ReadLine();

View 3 Replies View Related

C/C++ :: Infinite Loop If Enter A Non-numberic Character

Jul 28, 2014

it will produce the answer above..when user enter a nonnumberic character it will force the user to reenter again

do
{
cout<<"Min of the secret number : ";
cin>>min;
}while(cin>>min);
cout<<"Max of the secret number : ";
cin>>max;

this is my coding but it will auto jump out when i enter non-numberic character

View 1 Replies View Related

C :: Wrong Result In Integer Conversion To Little Endian

Feb 18, 2015

I am trying to convert uint32_t or unit16_t to chars in little endian. When I was reading the char s from binary file I used memcpy so I did not need to convert them, but now I try this:

Code:

static void write2Bytes(unsigned char ** pDestStr, uint16_t* item) {
(*pDestStr)[0] = ((uint16_t) item & 0x00ff);
(*pDestStr)[1] = ((uint16_t) item & 0xff00) >> 8;
*pDestStr+=2;


[code]...

In the last function I try either to cast to uint_32_t or unsigned char but in both case I got wrong values. The original binary string read from left: 0x36000003 (it is number corresponding to 48Mbytes).

And the result when casting to unsigned char is T000000 and T(>00 for uint_32. So what's wrong? I need to get some string with will be corresponding to 0x36000003. does this kind of convertion take a lot of compute performance when I one would use it offten (like when one would do convesions for bitmaps).

View 7 Replies View Related

C++ :: Best Way To Prompt User Again After Some Conditions Have Met

Mar 9, 2013

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;

[code]....

View 5 Replies View Related

C++ :: Prompt User For All Elements Of 3x3 Matrix

Dec 3, 2014

prompts a User for all elements of a 3x3 matrix. Your program should then print the matrix as well as the transpose of the matrix

View 1 Replies View Related

C++ :: How To Prompt User To Input Only Letters

May 12, 2014

I am trying to write a program to get user's input but only accepts alphabetic characters, nothing else and I want it to ask the user to enter a valid word until they have finally entered a valid one. I have the following code for it but it does not work properly.

void CheckBound (char word1[], int SIZE1) {
int i;
int w1[SIZE4]= {0};
int found;
for (i=0;i<strlen(word1);i++) {

[Code] .....

View 2 Replies View Related

C++ :: How To Prompt User Input Only Letters (a-z)

Mar 1, 2013

How do I have the user enter only letters?

#include <iostream>
#include <limits>
int getInt() {
int x = 0;
while(!(cin >> x))

[Code] ....

But this function prompts the user to only input integer values. I was thinking if I could maybe try tweaking with this one so that the user could only enter letters..no luck though. So how can I have the user input letters only?

View 3 Replies View Related

C :: What Will Happen If Enter A Char Instead Of Integer

Aug 21, 2014

Consider below statements:

int x;
scanf("%d", &x);

After running, It's supposed to enter an integer for x. what will happen if I enter a char instead of integer? which value will be in &x and x itself? I have a script and I get strange result while entering a char instead of integer for x.

View 5 Replies View Related

C++ :: Write A Password Prompt That Gives A User Only Certain Attempts

Mar 6, 2015

I'm trying to write this c++ programe:

Write a password prompt that gives a user only a certain number of password entry attempts, so that the user cannot easily write a password cracker.

Using FOR Loop. I know this can be easily done using while loop. But I want to know how to do it with for loop aswell.

Here is what I have so far:

Code:
#include <iostream>
#include <string>
using namespace std;
int main ()

[Code] ....

I don't see where the problem is.. The program just executes and does nothing.

View 9 Replies View Related

C :: Re-prompt User With Switch Statement Menu?

Sep 20, 2013

how to re-prompt a user with a switch statement menu that I prompted them earlier with. There are 4 options and after the user chooses an option the menu is supposed to pop up again unless the user chooses option 4, how do I do this? For reference I'll put up my source code.

Code:
int main(){
int init_bal,choice,balance,investment, donation;
printf("Welcome!

[Code]....

View 2 Replies View Related

C :: How To Prompt User To Scan Numbers Into Array

May 17, 2013

i need to prompt the user of my program to input numbers into an array so that later on these numbers can be added or subtracted with other numbers to form a new array. My problem is I don't know how to make the user input numbers which will then be saved into the array for later use. Here is the parts of my code that relate to the problem:

Code:

float Xv, Yv, Zv, Xu, Yu, Zu ;
float vector1[VECTOR_LENGTH] = {Xv, Yv, Zv} ;
scanf("%1f %1f %1f", &Xv, &Yv, &Zv);
printf("The first element in the array vector1 is: %3f
", vector1[0]);

The point of that printf function is to see if what they have entered is actually registering as what i want it to. This does not work however and the value for this always comes up as 0.

how to scan numbers into an array so that they can be used for later use?

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved