C :: If Put WRONG Input For INTEGER / Program Will Restart

Feb 15, 2015

I have a question about my program.. I would like to make a program that if you put "ABC" on INT, the program will restart again... below are my coding...but it not works..if i put ABC on INT, the "Invalid Mark.. please re-insert mark :" will repeat, repeat and repeat infinitely...

Code:

#include <stdio.h>
void calcul() {int mark;
char * grade;
if (!(scanf("%d",&mark))){printf("
}

[code]....

View 7 Replies


ADVERTISEMENT

C/C++ :: Yes Or No To Restart A Program Or End It

Aug 8, 2014

I just started learning c++ and got a problem now, i need a Y/N code, i case of yes the loop will restart and i case of no the program will end, Heres the code i got so far from trying to make my first steps.

#include <stdio.h>
void main() {
int a,b,c;
printf ("Zahl 1 Eingeben
");
scanf ("%i",&a);

[Code] ....

As u can see the other printf tasks are in german, but they are not important, the last one needs a Y/N "switch" y to restart the loop, and n to stop the program.

View 2 Replies View Related

C :: Use A Loop To Restart A Program

Feb 21, 2015

I've just started to learn C programming. In following program I need to use a loop, so at the end, it asks the user that if wants to try other numbers or not. If yes program restarts from beginning.

Code:
/*
A program who checks three positive integers to be 3 sides of a triangle and calculates the area and shows the triangle type.
*/

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)

[Code] .....

View 11 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++ :: Program With Do-while Loop To Restart Program And Validation

May 11, 2013

I am having problems at the end of the program with the do-while loop to restart the program and the validation.

#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <time.h>
using namespace std;

[code]....

View 3 Replies View Related

C++ :: Restart Program Every Time Type Move Of Blank Place?

Mar 5, 2013

I have to make a 8-puzzle and I got the algorithm i just dont know how to restart the program every time i type the move of the blank place in the 3x3 puzzle so i dont have to make 10000 lines to solve the puzzle

View 2 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

C++ :: Check Wrong Input Data

Jan 20, 2013

i'm making a for loop for a mini game which required the user to enter the input number.Let say if the user accidently entered a character instead of integer the whole program will go haywire so is there anyway to check for the error and prompt the user to input the data again?Here is the simple program...

for(row=0;row<4;row++)
{
printf("Enter Row%d:",row);
for(col=0;col<4;col++)
{
scanf("%d",&num[row][col]);
}

View 1 Replies View Related

C++ :: Cin Input Validation Returns Wrong

Jul 11, 2014

I have this function that is supposed to take a float as a parameter and then call the getLine() method to accept the users input. The function basically just checks to see if what the user input was of the same data type, if it is it returns the input value, if not then it keeps looping through taking new input until its correct. The problem is no matter what number you put in the output always returns as 140734799803512.

float InputValidation(){
float num;
string strInput;
while (true){
getline(cin, strInput);

[Code] ....

You also need to include <string> and <sstream>.

View 3 Replies View Related

C/C++ :: Program Takes Integer Input And Displays Each Digit On New Line From Right To Left

Jan 23, 2015

I'm trying to create a program that takes an integer input and displays each digit on a new line from right to left.

An example of this would be:

Enter an integer: 657
Digit (1): 7
Digit (2): 5
Digit (3): 6

So far I have this:

#include <stdio.h>
#include <math.h>
int main() {
int i, input, output;
printf("Enter an integer: ");
scanf("%d", &input);
if(input == 0)
printf("Digit (1): 0");

[Code] ....

It works perfectly fine, but I just learned that I am not allowed to use the #include <math.h> so I have to take out floor, log, and pow.

I'm pretty sure I have to do some sort of while or for loop to get the results, but how to do it.

View 6 Replies View Related

C :: Create A Program That Asks User To Input Integer Lengths Of Three Sides Of A Triangle

Sep 6, 2013

C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
int SideA;
int SideB;
int SideC;
}

[code]....

View 14 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

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++ :: Fees Showing Up Wrong On Program

Feb 19, 2014

I'm writing a program that shows check fees for different amounts of checks. My other fees are showing up right but the .10 cents is not. It's showing up as .08 cents per check when I run the program.

Oh yeah the + 10 is for a $10 fee

Code:
else if (checks < 20 || checks >= 0) {
fee = .10 * checks + 10;
cout<< "Bank service charge for the month is $ " << setprecision(4) << endl;
}

View 3 Replies View Related

C++ :: Program Should Input Each Student Grade As Integer And Store Grade In Vector

Jun 26, 2013

I get so close, and then it seems my brain shuts down ... I need to write a program that outputs a histogram of student grades for an assignment. The program should input each student's grade as an integer and store the grade in a vector. Grades should be entered until the user enters -1 for a grade. The program should then scan through the vector and compute the histogram. In computing the histogram, the minimum value for a grade is 0, but your program should determine the maximum value entered by the user. Use a dynamic array to store the histogram. Output the histogram to the console. For example, if the input is:

20
30
4
20
30
30
-1

Then the output should be:

Number of 4’s: 1
Number of 20’s: 2
Number of 30’s: 3

I can't quite get my output to look like that:

/* This program will display the histogram of student grades for an assignment */
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <conio.h>

[code]......

View 3 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# :: How To Take A Variable Value And Put It In Database To Recover After Restart

Jul 18, 2014

How can I take a variable value and put it in a DataBase to recover the value after a restart?

View 4 Replies View Related

C++ :: Game Loop Design - Restart Round?

Sep 30, 2013

I have a simple game loop.

while(true) {
//round initialization stuff
while(true) {
//capture input, make pieces move,
}
}

I am faced with the decision of what is the best way of restarting the game. The problem is, the condition for restarting a game is very, very deep inside the game's logic. So returning returning... is not an option, or at least, it ain't gonna be pretty.

So one of my considerations is to use a goto label, like so:

while(true) {
//round initialization stuff
while(true) {
//capture input, make pieces move,
} restart_round:
}

This seems to be the cleanest solution, since it allows me to fully reset the 'state' of the round, by first having all the destructors(pertaining to the round's objects) called, and then the constructors and other initialisation stuff.

Are there any subtleties that I am missing regarding this solution?

View 10 Replies View Related

C++ :: Input Integer To A String?

Oct 20, 2014

i wanna put an integer into a string for example:

Code:
string name;
int num=8;
name= "George"
//

I want in the end of George to pas the num variable i ve seen some examples but ive not yet come up with a solution like str.insert();

View 7 Replies View Related

C++ :: How To Check If Input Is Integer

Jan 15, 2013

I have an assignment to do..i have done it..but i need to do one more thing. Things sound like this: user inputs 6 integers program needs to check them if there are integer if not it has to output a message for the user if the input is integer it has to go further and work with the input. I have used this structure :

if ( ! ( cin >> temp ) ) {
cout<<"Input is not integer.This program will end ! "<<endl<<endl<<endl;
system("pause");
return 0;
}

Where I declared temp as being int since i started, the problem is after it gets the last input still waits for an input i will attach the source code if needed.

View 3 Replies View Related

C++ :: String Integer Value - Input / Output

Aug 14, 2013

Code:
Prompt the user to input a string,
and then output the sum of all the digits in the string.

Sample Run 1:
Input -> A111B222C
output -> 9

Sample Run 2:
Input -> ABC123XYZ32100000005555555555zzzzzz
output -> 62

View 1 Replies View Related

C :: Check If Input Is Integer Using Only Loops?

Nov 3, 2013

I have a homework that needs to verify if the input of the user is an integer using only loops no if statements Here's the problem:

A program is required that prompts the user for a number. The program will then print a series of asterisks to represent the number. If the user enters a number less than 1, the program stops. For example:

Enter a number: 5
*****
Enter a number: 3
***
Enter a number: 9
*********
Enter a number: 0

All user input must be validated:
- Check for non-numeric input when reading numeric input
- Check that values entered are within the expected range for their purpose, or in range based on the requirements statement

View 10 Replies View Related

Visual C++ :: Check If Input Is Integer Or Not

Jun 20, 2014

I have been trying to make a very simply programme that checks if the inputted information is an integer or not (i.e: that it contains no other characters).

I have tried using the isdigit function (but this only works for single characters). I have tried cin.clear, cin.ignore (1000) but this doesn't work either..

Any effective way to check if x in the following programme has been entered correctly

#include <iostream>
using namespace std;
int main() {
cout << "Please enter an integer (positive or negative)" << endl;
int x;
cin >> x;
HERE I WOULD LIKE CODE TO CHECK IF THE USERS INPUT IS VALID
}

View 2 Replies View Related

C/C++ :: Input Float And Integer And Save It To Txt File

Mar 20, 2014

i am writing a program that requires me to write am input a float and an integer and save it to a txt file. When i try to compile my code i get an error "assignment from incompatible data type". ?

int *intconstant;
float *floatconstant;
int *value;
struct FILE *infileptr, *outfileptr;
infileptr = fopen("/home/brinkmann.brendon/assign14data.txt", "r");
outfileptr = fopen("/home/brinkmann.brendon/assign14report.txt", "w");

[Code]...

View 14 Replies View Related

C++ :: Making Diamond Out Of Asterisks Based On Given Odd Integer Input

Sep 6, 2014

I have been tasked with making a diamond out of asterisks based on a given odd integer input. For some reason the bottom half of my diamond will not print. I'm not sure as to why.

Here is my code:

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

using namespace std;
int _tmain(int argc, _TCHAR* argv[]){

[Code] ....

View 2 Replies View Related

C++ :: Separate Input Integer Into Its Individual Digits And Print

Apr 18, 2013

Write a full C++ program that inputs three-digit integer, separates the integer into its individual digits and prints the digits separated from one another. For example, if the user types 549, the program should print;

5 4 9

View 5 Replies View Related







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