C++ :: How To Trap Integer Inputs Using While Loop

Sep 30, 2014

This is just a portion of my program and I want to trap the integer inputs using while loop.

cout<<"
Enter the name : ";
while(/*integer input or not in character*/) {
//Invalid Input!
}
cin.ignore();
cin.getline(name, 100);

View 1 Replies


ADVERTISEMENT

C++ :: How To Trap Negative Integer Inputs In Program

Jun 30, 2014

A program that asks 10 positive integers and classify them as odd or even positive integer inputs. The algorithm has to trap negative integer inputs. The output will be displayed in two columns. ODD and EVEN.

here's my program code...

#include<iostream>
using namespace std;
main() {
int countA;

for(countA=0;countA<=10;countA++) {

[Code] ....

View 3 Replies View Related

C++ :: How To Trap Using While Loop

Sep 8, 2014

If the item to be entered is smaller (in value) compared to the last item, the input will be disregarded as it is considered invalid entry.

Here's my code...

#include<iostream>
using namespace std;
int main() {
int choice, num, item;
while(1)

[Code] ....

View 1 Replies View Related

C++ :: Take Integer Score Inputs From Keyboard Into Array

Apr 2, 2014

This program is supposed to take integer score inputs from the keyboard into an array and use a sentinel of -999 to end the process.It should call a show() function which passes the array and displays the name and number of the integer for the output.

# include <iostream>
using namespace std;
int main() {
int score(double array1[], int numbers);

[code].....

I am getting an error in the for loop r<number which states "Error identifier "numbers" is undefined" and on my array1 "Error identifier "array1" us undefined" also in my for loop.

View 3 Replies View Related

C++ :: For Loop - Summing Numbers (Inputs From User)

Aug 2, 2013

Write a program that computes a running sum of inputs from the user, terminating when the user gives an input value of 0

Using a while loop - no problem. Its only when I try to code it with a for loop that the program doesn't terminate with a 0 input. It terminates with a -1 input!!

while loop

#include <iostream>
using namespace std;
int main() {
float input=1;
float sum = 0;

[Code] ....

View 4 Replies View Related

C :: How To Terminate A Loop If User Inputs Blank Space In A String Or Press Enter

Jan 28, 2015

Code:

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main(void) {
int i;
char *str;
int len = 1;

[Code]...

View 3 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++ :: Finding The Largest And Smallest Integer In A Set Using While Loop

Sep 29, 2014

I've been working at this for awhile and it seems like it should be correct but it isn't giving me the desired output. Here's my code.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>

[Code]....

And here is my output when I run the program.
75
Max: 90
Min: 0

Press any key to continue . . I am reading from a file in this program which contains a set of 30 numbers and it has the average correct and the max correct but the minimum number in the set is 56 however it keeps giving me a zero for the min.

View 4 Replies View Related

C/C++ :: For Loop To Print Given Character Number Of Times Specified By Integer

Feb 11, 2014

The function uses a "for" loop to print the given character the number of times specified by the integer.

How can I make a for loop to do that?

So.. my code looks like this:

// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {

[Code] ....

So.. here is my error:

Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6

View 3 Replies View Related

C :: Assign Integer Value To Unsigned Char Array But It Is Not Storing Integer Values

Oct 25, 2013

I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet

Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}

The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.

View 9 Replies View Related

C++ :: Changing Integer Into New Integer With Simple Mathematical Operations?

Jun 15, 2014

changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).

View 4 Replies View Related

C/C++ :: Converting 8-byte Integer To String Based Integer

Oct 15, 2014

Complete the function myitohex so that its converts 8-byte integer to string based hexadecimals.

Ex: printf("0x%s",myitohex(64,hex)); should printout "0x40" on the screen
char *myitohex(uint8_t i, char *result){
???
return result;
}

I wrote:

#include <stdio.h>
#include <stdint.h>
char *myitohex(uint8_t i, char *result){
*result = i + '0';

[Code] ....

0xp gets printed out which is wrong. I think *result = i + '0'; is wrong. What changes should i do on this row ?

View 4 Replies View Related

C++ :: The Max Of N Inputs That Is Divisible By 3

Nov 29, 2013

Code:
#include <stdio.h>
int main(){
int A, B;
char decision;
printf("Do you have an integer to input? [Y/N]: ");
scanf("%c",&decision);
if(decision=='Y' || decision=='y'){

[Code]....

After entering a single integer, it doesn't scan again for another integer. What's wrong?

I'm using a mac btw, if that makes a difference with Ubuntu/Linux.

View 8 Replies View Related

C :: How To Read Inputs From File

Dec 7, 2014

I have learnt recently how to use fgetc, fputc, fputs, fgets but still I am not able to figure out how to read values from a file like for example:

12 14 1928 32993932
17 98
166 109 201

These are separate integers & i want to read them and then manipulate these individual integers like going for 2*I1, 4*I2 and so on where I1 and I2 are 12 & 14.

View 2 Replies View Related

C :: 2 User Inputs For Calculation

Apr 9, 2014

I want to have calculations take place inside a switch statement that calls the appropriate function. The menu portion of the program works well, but I can't figure out how to let the user actually input 2 different numbers to the functions. My questions are:

1. If I use scanf to assign values to the variables, what determines end of input to each variable? (ie.. scanf("%d%d", &a, &b) what is the end of a, what is the end of b?)

2. Should I assign the variables to user input inside the switch, or try to do it in the functions below?

3. Is there something I haven't thought to ask that will screw me over? I'm really new to this.

Code:
#include<stdio.h>
int add(int b, int a);
int mult(int b, int a);
main() {

[Code] ....

This really was a test of multilayer menu, but I want to add functionality if I can.

Changed a variable before posting and didn't change all the conditions testing it.

View 3 Replies View Related

C :: Keep User From Putting Inputs

Sep 27, 2013

On my program I use a counter to count to 10, then i ask for a string, in this case "yes" or "no", during the count, i want to keep the user from putting inputs in, due to the fact that if they put both "yes" and "no" before the program reads the string.

Code:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
}

[code]....

View 3 Replies View Related

C :: Skips Inputs Instead Of Inputting Last Name

Mar 2, 2014

it skips the input phase,, instead of inputting the last name it goes directly to the firstname then middle initail and street name are working fine but it skips the street name then goes to city and so on....

Code:

char l[50], f[50], m;char strtname[50], cty[50], cntry[50];
int strtnum, zp, i;
system("cls");
printf("Enter Last name:");
gets(l);
printf("
Enter First name:");
}

[code]....

View 3 Replies View Related

C :: How To Put What The User Inputs Into Array

Jul 23, 2014

I have a project that requires I take user input from menu options and put it into an array which I will average out. I can set the menu up I think, but I cannot understand how to put what the user inputs into an array. Granted I just took the lecture on arrays today. Also we can only use functions to do the work.

View 9 Replies View Related

C :: How To Scanf Inputs Into Array

Nov 23, 2014

I don't know how many numbers will be the input only that its going to be up to 10000. EOF should be active. I tried it like this:

Code:

int i = 0;
int del[10000]
while (scanf("%d",del[i])!=EOF)
{
i++;
}

But it seems the value of i doesn't increment, could you provide some tips on how to scanf the inputs into an array if I don't know how many numbers will I have?

View 7 Replies View Related

C :: Check For Browser Inputs?

Oct 26, 2013

Any chances for a c program to check for browser inputs?

View 1 Replies View Related

C++ :: Using Cin That Accept Multiple Inputs

Feb 14, 2013

For a program I am required to use a cin that accepts 4 variables. The first describes a function such as add(), remove(), print(), or quit(). The problem is that to use add() I need to input all 4 variables but for remove(), only 2 variable input is needed.

I want the input to be "add 9 James Bond"
or be "remove 341"

Here is my current code.

int command(string command, int Id, string first, string last){
while (command != "quit"){
cout << "customers> ";
cin >> command >> Id >> first >> last;
if (command == "add")

[Code] .....

View 1 Replies View Related

C++ :: How To Set Color On Inputs And Outputs

Feb 10, 2013

I am new to C++ and I want to learn how to set color a particular color for the users input and output. For example, I want to display the users input as green, and their output as red.

View 2 Replies View Related

C++ :: How To Combine Inputs Using If Statements

Jul 19, 2013

How to combine the if statements?

cout<<"Enter a sale number"<<endl;
cin>>rec.sale;
if(cin.fail())
{
cout<<"Enter a number"<<endl;
cin>>rec.sale;
}

[Code]...

View 13 Replies View Related

C++ :: Use Library Management Inputs?

Feb 1, 2013

How to use library management inputs

View 2 Replies View Related

C++ :: How To Insert Many Inputs In Same Line

Feb 23, 2013

Make a C++ Program that will use nested if else and any looping statement to display the following a certain number of times depending on how many times the user wants it to do so.

Input Values:
1. Name of employee
2. Position in the company
3. No. of hours worked
4. Rate per hour
5. Overtime hours

Required Output:
No. Name Position Rate per No. of hours Basic No. of overtime Overtime
hour worked Pay hours Pay
1. Juan Manager 160 140 22400 10 2100

Computations:
basic pay = no. hours worked x rate per hour
overtime = overtime hours x 150% of rate per hour

Just asking how can I input the name, position, rate per hour, overtime hours and hours worked in a horizontal manner?
Because I need to achieve the required output.

View 1 Replies View Related

C++ :: String Inputs On If Statements

May 26, 2014

How to make an input with a string thats part of an if statement. How I think it should be done :

#include <iostream>
#include <string>
using namespace std;
int main() {
string choose;

[Code] .....

But I get a strange warning (not an error, but something that is like "just letting you know" i suppose) and when i enter in ss or SS or aa or AA, it breaks my app.

View 7 Replies View Related







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