cout << "Enter a phone number(Enter Q to quit): ";
cin >> a >> b >> c >> d >> e >> f >> g >> h;
In this program I'm trying to get a phone number. If the user enters a q it's supposed to exit. The program is for a programming class and the instructor wants us to not use arrays. The problem is, if the user enters a q, the program still wants the other 7 variables. I can't make 8 separate cin statements. The program won't exit when I enter a q, and I can't figure out how to fix this problem.
> How do I check one variable before inputting the others on the same line?
Read the first variable && check it to see if we should proceed && read the remaining variables.
Or: Read the first variable if we should proceed is true then read the remaining variables.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
int main()
{
char a,b,c,d,e,f,g,h ;
while( std::cout << "Enter a phone number(Enter Q to quit): " &&
std::cin >> a && a != 'Q' && a != 'q' &&
std::cin >> b >> c >> d >> e >> f >> g >> h )
{
// whatever
}
}
Write a program that simulates the dialing of a phone number.
A user will input an 8-place number, for example: 359-3177 (note that the hyphen is considered a digit).
The rules for entering phone numbers follow.
• 8 places
• It may have numbers, letters, or both.
• The phone number cannot begin with 555.
• The phone number cannot begin with 0.
• The hyphen must be in the 4th position.
• No other characters (@#$%^&*()_+=\|/><etc.) are allowed.
• If a letter is entered, its output will be a number (check your phone pad).
• Enter Q to Quit.
The focus of this project is supposed to be on functions. We are to use a readDials function to input the phone number, a toDigit function to convert the user input into numbers, and an acknowledgeCall function to output the number. The instructions specifically say to make 8 separate char variables and not to use an array.
He won't be able to use 'q' to quit. Because there is a chance the number has a q in it. So you may want to prompt ppl to use lower case letters when inputting a letter. After tinkering with this the code I got to work was this. I truncated it to save some space.
wish i could of made the code shorter but couldnt use arrays, dont know why your professor doesn't want you to use them. If you are just gonna use this a tip to type in the other num rules is to highlight the info paste it a bunch of times highlight em again go to edit and do replace num1 with num whatever then do selection and replace all.