C :: Give Error Message If User Inputs Wrong

Nov 2, 2013

Code:

#include<stdio.h>
void main
{
int i;
int marks[10];
}

[code]....

how to give error and ask user to re enter if user enter other then a number?

View 6 Replies


ADVERTISEMENT

C++ :: If User Inputs Letters / Words Instead Of A Number Give Error Message

Jan 11, 2014

I have created an error message if the user inputs the wrong selection number

if (choices < 1 || choices > 5)
{
cout << "
Please Enter a number between 1-5
";
}

How would i create a error message if the user inputs letters/words instead of a number.

View 5 Replies View Related

C++ :: Program Compiles Successfully But Calculations Give Wrong Answer

Feb 11, 2013

I'm using MSVC++ and it builds sucessfully but somewhere something is obviously messed it. Once i try to debug it just shows weird numbers.

int k=0; //could this be the problem??? since 0 would be over writing any given value. but if i leave int k; it showsa warning and MSVC would count that as an error

#include "stdafx.h" //Header file section
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//structure declaration
struct menuitemtype

[Code] ......

View 14 Replies View Related

C :: Gender Program That Interpret M And F Inputs And Prints Guy / Girl Message

Apr 10, 2014

How do I write a program that'll interpret "M" and "F" inputs and print a "you're a guy" or "you're a gurl" message?

Code:
#include <stdio.h>
#include <conio.h>
char gender;
char main(void) {
printf("type M or F

[Code] ....

View 5 Replies View Related

C/C++ :: Program To Take A Number From The User And Give Reduced Sum

Dec 30, 2014

i have only recently got into programming. i have this homework assignment that is frying my brains, the program needs to take a number from the user and give the 'reduced' sum. for example: if the user enters 888 then the sum should be: 6. it takes the number and adds its digits im just looking for a direction to where my problem is

#include "iostream.h"
int reduction (int number) {
return number/10+number%10;
}
int main() {
int number,loopcount;
cout<< "please enter a number"<<endl;
cin>>number;

[Code]...

View 2 Replies View Related

C++ :: Give Appropriate Color Code For Resistor After User Input

Sep 18, 2013

I am in the process of writing a program that will give the appropriate color code for a resistor after the user enters an integer value for the resistance needed and selects the tolerance form a list. My question is this: Is there a way to allow the user to enter a value such as 75000 and C++ use each digit separately, as if they entered 7 [enter], 5[enter], 0 [eneter]... and so on? But, then use the entire value as an integer too? Also, it should read a value such as: 45835, as 45000, or 1843 as 1800.

View 1 Replies View Related

C++ :: Correct Answer From File - Cin Getting Wrong User Input

May 31, 2014

So I'm writing a program that will read a text file and it will do certain "functions" the text file will be like a game, and the program will be able to run many different games. The problem i'm having is in one of the "functions" i believe it's the one meant to get a correct choice from a file and a user input and put them into strings, it gets the wrong input. I know this because i tested both strings the "function" writes too. it gets the correct file answer but the user input is always "c" for some reason.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int progfiles() {

[Code] ....

This is the code, most likely the section that is surrounded with "///" contains the problematic "functions." This is the command Line output...investigate why they're dieing or continue on your journey?(i-investigate/c-continue) got input and answer

i
c
i
Press any key to continue . . .

The got input and answer are tests to make sure it got both, the first 'i' is my input, the 'c' is what it says my input is, and the 'i' is the correct answer from the file. this is the part of the file that the program reads to get that output

"1 Do you want to go investigate why they're dieing or continue on your journey?(i-investigate/c-continue) 2 8 i 7 3 4 You continue on picking up speed to get to the egg first.. and.. Oh No, You accidentally bumped into the walls! 2 12 5 1 You go over, and as you realize the walls are acidic and that's why the other sperm are dieing.. 2 6"

View 3 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 :: 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/C++ :: How To Get User Inputs Into Array

Mar 16, 2014

How to get user inputs into an array. I have to get 10 user inputs into the array and I'm trying to use a loop but once I run it it crashes whenever you input the first value. This is my absolute first time working with arrays and I've been trying to do research

#include <stdio.h>
#define SIZE 10
void Input(const int array1[]);
void Calculations(int array1[], int average);
void Output(int array1[], int average);

[Code]....

View 2 Replies View Related

C++ :: Error Message While Debugging

Mar 17, 2013

I'm getting an error message that I can't seem to fix. The error clearly states that during the link aspect of the debugging and build there is an error that says that the stdio.h file is either missing, invalid or corrupt. When I try to program using any of the other headers I'm getting the same error. The files are there I can see them in the include folder, so I'm asking what can I do to fix all these headers and beware I am a beginner at programming and using any kind of compiler.

This is the error I receive.
1>------ Build started: Project: hello, Configuration: Debug Win32 ------ 1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========

This is the compiler I am required to use for an online course and all instruction is given for the Microsoft visual 2010 express edition. Also the only file I think that's being referenced is the #include <stdio.h>.

View 1 Replies View Related

C++ :: Add Error Message If Cin Is Not A Number

Dec 13, 2013

#include <iostream>
#include <stdlib.h> //used for random numbers
#include <time.h>
#include <string>
using namespace std;
int main() {
int bridgeWidth ; //set bridge width to any number

[code].....

View 3 Replies View Related

C++ :: Error Check - Only Alphabetical Inputs

Jan 11, 2015

How can i set up an error check so only letters are entered? I know how to do it for numbers but how to make it so it only allows a-z inputs.

View 3 Replies View Related

C :: Picking And Choosing Between User Inputs

Jul 31, 2013

I have recently looked into a self created project where I wanted to compare user input against a list of strings in an external file. That has since been completed to my great satisfaction, however it did throw up some interesting issues in my knowledge and understanding of user input..What is the best way to pick up user input i.e scanf,stdin etc. and when should either be used and can a mixture of types be used, and if so, when and why.

A quick program to take different input methods and display differnt output method (obviously corresponding i.e scanf/printf - fgets/fputs)

My first pothole came when I have setup the method for scanf - fine. Then I setup the method for fgets(test,100,stdin) for example and the fgets method no longer picks up stdin from the user..

View 3 Replies View Related

C++ ::  calculating Sum Of Numbers Between Two User Inputs

Mar 17, 2014

How to calculate the values between numbers that a user types in.

Write a function which takes two parameter of integer type and both parameters are positive integer. These number should be provided by the user of your program. The first parameter is lower than the second parameter. You function should be able to calculate the sum of the square of each of the numbers between the two inputs and should display that. Please write a main function to display the working of your function. Call the function at least three times by using some loop in the main function.

View 2 Replies View Related

C/C++ :: Linked List Inputs From The User?

Sep 8, 2014

#include <iostream>
using namespace std;
void insert(int data, int positionOf_n);
void print();
struct node {
int data;
struct node *next;

[code]....

this is the original code which use the insert function call in the main as predefined that doesn't allow the user to input the value that they want

#include <iostream>
using namespace std;
void insert(int data, int positionOf_n);
void print();
struct node {
int data;

[code]....

and this the code which i tried to replace the limitation of the above code by using two for loops in the main function instead of the <insert(5,2)> from the above code which allow the user to insert it own values to the linked list, but it keeps crashing.

View 4 Replies View Related

C++ :: Error Message - Assertion Failed

Nov 12, 2013

I got this message after i delete allocated class object, should i check the deleting? if it's object what is the correct way to delete/delete[]?

theCars[nToDel] is a static array of pointers

bool Cars::deleteElement(int nToDel) {
if (theCars[nToDel] != NULL) {
delete[] theCars[nToDel];
theCars[nToDel]=NULL;
inUse--;
return true;
} else
return false;
}

View 3 Replies View Related

C++ :: How To Check User Selection (yes / No) On Message Box

Feb 10, 2013

How can you tell what button(yes/no) on a message box is clicked? Below is what I have right now but I am getting errors.

if (MessageBox(NULL,"The Message", "The Title", MB_YESNO) == IDYES){
do something
}

View 7 Replies View Related

C :: Stomp Size Of Array With What The User Inputs?

Apr 5, 2013

How can I stomp the arr size of 50 with the value the user inputs? The function doesn't sum up the even integers from 0 to the value the user inputs. Instead it sums up exactly that many even integers.

Is there a way I can stomp the size of the array with what the user inputs so that the sum calculation never goes past the value the user inputs?

Code:
void sumIntegers () {
int arr[50];
int i = 0;
int num = 0;
int sum = 0;
printf("

I want to sum up even integers <= 50.

[Code] .....

View 4 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++ :: Create Fibonacci Sequence With Some User Inputs

Aug 26, 2013

I'm trying to make a fibonacci sequence with some user inputs. I'm using arrays for this, the user inputs are for the Nth term and the starting number (as in the number in front of 0).

My problem is that when the program runs it's an infinite loop which constantly prints the starting number. Which, I think, means that my WHILE loop isn't coming to an end and my 'count' variable isn't increasing.

#include <iostream>
using namespace std;
int main() {
int start;
int term;
cout << "Input a starting number for the sequence: ";
cin >> start;
cout << "
Enter the Nth term for the sequence to reach: ";

[code].....

View 4 Replies View Related

C++ :: Templates User Inputs Dynamic Array?

Nov 12, 2013

This code is from my text book it shows how to implement code that is embedded I have modified it somewhat but I was wondering how I could get the user to implement the size of the array and enter the integers with the size of array that was implemented.

#include<iostream>
#include<cstdlib>
#include<iomanip>
using namespace std;

[Code].....

View 1 Replies View Related

C++ :: Random Number Generator - How To Get User Inputs

Sep 10, 2013

I want to program a program that produces a random number between 1-10, then if the number is correct, says like HEY GOOD JOB and if its not says try AGAIN! also, at any point the user can quit by typing in X.

I know that I can use stuff like cout << "Hey put in a guess now" to prompt the user but I dont know how to accept inputs.

For example, how do I use scanf to do this?

I know that if I use scanf, it takes in a value, but where the heck does it store it?

eg. scanf(%s,guess);

Is that valid? I get an invalid expression error when trying to use that in C++.

View 3 Replies View Related

C++ :: Determines Whether A Number Which User Inputs Is Prime Or Not

Jan 11, 2015

I am fairly new to C++ and I am trying to write a code that determines whether a number which the user inputs is prime or not. I have the code, but when I run it all it actually does is report odd numbers as prime and even numbers as not prime.

#include <iostream>
using namespace std;
//declaring variables//
int i;
int num;

[Code] ....

View 7 Replies View Related

C++ :: Create A Grading Program That The User Inputs A Name?

Feb 17, 2013

I want to create a grading program that the user inputs a name and then on that value (name) there is a vector of doubles to represent his/her mark and then calculates an average how would I go about doing this?

View 1 Replies View Related







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