logo
down
shadow

Using cin.get() doesn't seem to read the character I'm expecting. What's wrong?


Using cin.get() doesn't seem to read the character I'm expecting. What's wrong?

By : Drew Faber
Date : October 16 2020, 03:08 PM
it helps some times I would recommend you to use cin>> instead of cin.get() as the cin.get() after every initialization is there to "grab" the newline character that gets put in the stream every time you press enter.
code :
#include <iostream>
using namespace std;

int main () {

int mi;

cout << "1) Area of Circle" << endl;
cout << "2) Character Detection" << endl;
cout << "3) Capitalization 1-3-5" << endl;
cout << "4) Binomial Roots" << endl;
cout << "0) Quit" << endl;

cin >> mi;

switch (mi) {
    case 2:
    {
        char c;
        cout << "input a character:  ";
        cin>>c;
        cin.ignore(); /////// unsure if using this properly
        if ('a' <= c && c <= 'z') {cout << "c is lower case" << endl;}
        else if ('A' <= c && c <= 'Z') {cout << "C IS UPPER CASE" << endl;}
        else { cout << "C is not a letter" << endl;}
    }
        break;
}


return 0;
} 


Share : facebook icon twitter icon
Write a program which takes a character string input and returns penultimate character. Whats wrong with my code?

Write a program which takes a character string input and returns penultimate character. Whats wrong with my code?


By : user7766998
Date : March 29 2020, 07:55 AM
it helps some times Size is a function, not a variable. Therefore, it would need arguments, like size(X) which would return [1 5] for a 1x5 matrix.
Try X(length(X)-1) or more concisely, X(end-1)
Whats wrong with my code? The backwards loop doesnt work (Option 2)

Whats wrong with my code? The backwards loop doesnt work (Option 2)


By : nguyen tien thanh
Date : March 29 2020, 07:55 AM
it should still fix some issue Your for loops aren't exactly the same.
The first option goes through { 0, 1, ..., 7 }
code :
for (index = 7; index >= 0; index--) {
    ...
}
Puppeteer function doesnt run whats wrong?

Puppeteer function doesnt run whats wrong?


By : user3148472
Date : March 29 2020, 07:55 AM
help you fix your problem ,
I thought Promise.all() waits for everything in order
code :
await login()
await setStartDate()
await setEndDate()
await confirmSchedule()
Whats wrong in this asp.net code? Textbox value doesnt set

Whats wrong in this asp.net code? Textbox value doesnt set


By : Rick Stephens
Date : March 29 2020, 07:55 AM
I think the issue was by ths following ,
How can I read a character that is mistakenly typed at the end of an expecting floating point number?

How can I read a character that is mistakenly typed at the end of an expecting floating point number?


By : Sourav Ghosh
Date : March 29 2020, 07:55 AM
I wish this helpful for you
How can I read a character that is mistakenly typed at the end of an expecting floating point number?
code :
// return 1 on success
// return EOF on end-of-file or input error
int getVector(vect *v) {
  char buf[100];  // make this 2x expected max size
  vect temp;
  bool repeat = true;
  while (repeat) {
    printf("Enter a vector in the format x y: ");
    fflush(stdout);
    if (fgets(buf, sizeof buf, stdin) == NULL) {
      return EOF;
    }
    int n = 0;
    sscanf(buf, "%f%f %n", &temp.x, &temp.y, &n);
    // If scanning was incomplete or did not end at the end of the string, then fail
    if (n == 0 || buf[n]) {
      printf("  >Input Failure!\n");
    } else {
      repeat = false;
    }
  }
  *v = temp;
  return 1;
}
Related Posts Related Posts :
  • Shared pointer [] operator and ++ operator
  • standard way to put static objects together
  • Delete Elements from Vector Inside Loop
  • c++: How to flip the binary values of each bit in int
  • Strange Parent ID
  • How to fail static assertion if a class doesn't have default visibility
  • error in sscanf while scanning char[] and int
  • C++ Interfacing queue or priority_queue as template parameter of a class
  • JUCE - Member Function Not Viable: 'this' Argument Has Type const
  • Saving a brute force result for future use?
  • which header file contains ThrowIfFailed() in DirectX 12
  • 2D array pass in a function without Define (M x N) globally
  • Converting string to TDateTime in C++Builder 2009
  • Excel C API: Is there an Excel v4.0 macro function to test if a sheet is hidden?
  • std::setw for the whole operator<< of user-defined type
  • How do I setup an ODBC connection to perform multiple querys(SQLExecDirect) in c++?
  • Vectorization of modulo multiplication
  • C++ 11 thread class member function in for loop gives segmentation fault
  • Mesh boolean operation with CGAL
  • Best way to fix type conversion warnings in c++
  • How do to have a template deduce its parameters
  • Passing auto as a parameter (for pointer to object)
  • C++: MFC Application on both Windows 10 x64 & Windows 7 x64
  • Read stdin with C++ and concatenate inside string
  • No longer unable to retrieve data from QIODevice after calling readAll(). Buffer flushed?
  • g++ command line macro define byte stream
  • Why won't my variadic macro accept no arguments correctly?
  • Clang adds noinline attribute to all functions when emitting LLVM IR
  • as rptr->num=30 is same as (*rptr).num=30 but*((*rptr).ptr).name does not work why?
  • How to use get() multiple times in c++ 11 future or how to get a vector values?
  • libstdc++ cannot find thread file on Mac
  • Check if macro is odd in c++
  • What is the fastest method to create uniform random numbers in c++
  • C++ - difference between first two elements
  • Repeated inheritance and static_cast
  • C++ template class, how to declare a copy constructor for a specific situation?
  • return 1 return 0 in case of factorial
  • Best way to hash a vertex
  • How append rectangle to QGraphicView
  • Extract points from PointCloud with PCL
  • Handling gcc's noexcept-type warning
  • Floating point math going wrong using cpp_bin_float from boost::multiprecision
  • Optimise a recursive function
  • Omit the newline character in reading file with c++
  • How should I manage ::std::cout after changing file descriptor 1 to refer to a different file?
  • Inheriting traits classes after a slight change in template type
  • How do I specify different libraries for a static Qt project?
  • Parent class turned into subclass Pointers C++
  • alternative of if else-if else statement c++
  • SetProgressValue() not working within ConEmu
  • Debugging compiler failure
  • Why My Applicaion cannot display unicode character correctly?
  • "Destructor already defined" with a specialized destructor
  • Is there a way to replace a function within a method in c++
  • MySQL c++ connector how to retrieve auto increment keys from insertion query
  • What is minimal work needed to reconnect existing socket to new server?
  • In c++ how do I go about using pointers to get the average of an array?
  • How to print to file using ostream_iterator?
  • C++ template class with non-type parameter: how to overload the assign operator?
  • why compiler is not showing error when I have two functions one will take base class and one will take derived class as
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com